﻿
###TRIGGER LIST

# has_strong_religious_conviction_trigger
# is_christian_trigger

###DOCTRINE BASED###
# is_weak_claimant_due_to_gender_trigger
# can_be_combatant_based_on_gender_trigger
# can_be_clergy_due_to_gender_trigger
# faith_is_aniconic_trigger
# relation_with_character_is_incestuous_in_rite_trigger 	- Relation would be shunned under the rite
# relation_with_character_is_incestuous_in_my_rite_trigger 			- Relation would be shunned under the rite of character you use trigger in
# relation_with_character_is_incestuous_in_my_or_lieges_rite_trigger - Relation would be shunned under the rite of the character you use trigger in or their liege's rite
# rite_allows_marriage_consanguinity_trigger
# relation_with_character_is_sodomy_in_rite_trigger
# relation_with_character_is_sodomy_by_my_rite_trigger
# relation_with_character_is_sodomy_in_my_or_lieges_rite_trigger
# trait_is_shunned_in_rite_trigger
# trait_is_criminal_in_rite_trigger
# trait_is_shunned_or_criminal_in_my_or_lieges_rite_trigger
# has_negative_attitude_towards_trait_trigger
# secret_is_shunned_in_faith_trigger
# secret_is_criminal_in_faith_trigger
# secret_is_shunned_or_criminal_in_my_or_lieges_faith_trigger
# religion_has_angels_trigger
# highgod_is_passive_trigger
# highgod_is_active_trigger
# is_reincarnation_trigger
# holy_order_1000_request_target_trigger 		- Is this ruler a valid target for a Military Order to request land from?

###HERESY TRIGGERS###
# is_valid_heresiarch

###RELIGIOUS INTERACTIONS###
# can_take_religious_vows_trigger


# CHECK A NUMBER OF RELIGION-RELATED CONDITIONS TO DETERMINE HOW STRONG OF A BELIEVER THEY SEEM TO BE
has_strong_religious_conviction_trigger = {
	NOR = {
		has_trait = cynical
		has_trait = excommunicated
	}
	OR = {
		has_trait = zealous
		has_trait = pilgrim
		has_trait = devoted
		has_trait = sayyid
		has_trait = saoshyant
		has_trait = savior
		has_trait = divine_blood
		has_trait = blood_of_prophet
		has_trait = faith_warrior
		has_trait = saint
		has_trait = herald
	}
}

is_christian_trigger = {
	faith = { religion_tag = christianity_religion }
}

# Not-non-XYZ triggers allow us to check for specific historical faiths whilst still defaulting to something positive for variant faiths.
## E.g., looking to see if something would only be of interest to Catholics, but if we're dealing with a player-made heresy, still return true. This way mechanics will default to on rather than off (still likely to result in weird GHWs, but at least less random ones).
not_non_catholic_standard_christian_faith_trigger = {
	NOR = {
		this = faith:orthodox
		this = faith:miaphysitism
		this = faith:armenian_apostolic
		this = faith:iconoclast
	}
}

not_non_orthodox_standard_christian_faith_trigger = {
	NOR = {
		this = faith:catholic
		this = faith:miaphysitism
		this = faith:armenian_apostolic
	}
}

not_non_coptic_standard_christian_faith_trigger = {
	NOR = {
		this = faith:catholic
		this = faith:orthodox
		this = faith:iconoclast
		this = faith:armenian_apostolic
	}
}

not_non_armenian_standard_christian_faith_trigger = {
	NOR = {
		this = faith:catholic
		this = faith:orthodox
		this = faith:iconoclast
		this = faith:miaphysitism
	}
}

is_weak_claimant_due_to_gender_trigger = {
	OR = {
		AND = {
			$RITE$ = { rite_has_parameter = female_claims_are_weak }
			$CHARACTER$ = { is_female = yes }
			NOT = {
				$RITE$ = { rite_has_parameter = tenet_hyperdulia_female_claims_are_strong }
			}
		}
		AND = {
			$RITE$ = { rite_has_parameter = male_claims_are_weak }
			$CHARACTER$ = { is_male = yes }
		}
	}
}

can_be_combatant_based_on_gender_trigger = {
	custom_description = {
		text = "can_be_combatant_based_on_gender"
		object = this
		subject = $ARMY_OWNER$
		OR = {
			trigger_if = { # Has the Royal Court and thus can modify pillars
				limit = {
					has_dlc_feature = diverge_culture # Can modify pillars
				}
				trigger_if = {
					limit = {
						$ARMY_OWNER$.culture = { has_cultural_parameter = martial_custom_male_only_combatant }
					}
					is_male = yes
				}
				trigger_else_if = {
					limit = {
						$ARMY_OWNER$.culture = { has_cultural_parameter = martial_custom_female_only_combatant }
					}
					is_female = yes
				}
				trigger_else = {}
			}
			trigger_else = { # Does not have the Royal Court and thus combatant is governed by faith
				OR = {
					$ARMY_OWNER$.rite = { rite_has_parameter = combatant_can_be_either_gender_if_no_roco }
					AND = {
						$ARMY_OWNER$.rite = { rite_has_parameter = combatant_must_be_male_if_no_roco }
						is_male = yes
					}
					AND = {
						$ARMY_OWNER$.rite = { rite_has_parameter = combatant_must_be_female_if_no_roco }
						is_female = yes
					}
				}
			}
			AND = {
				# No need to gender diversify this: if they're a right-gender shieldperson of the culture, then they've already got permission to fight from the previous AND conditions.
				has_trait = shieldmaiden
				$ARMY_OWNER$ = {
					culture = { has_cultural_parameter = has_access_to_shieldmaidens }
				}
			}
			# Event-based special exceptions
			OR = {
				has_character_modifier = ignores_gender_army_rules
				has_character_modifier = mpo_destined_leader_modifier
			}
			AND = {
				prowess >= 10
				$ARMY_OWNER$.culture = { has_cultural_parameter = high_prowess_ignores_knight_restrictions }
				NOT = { $ARMY_OWNER$.culture = { has_cultural_parameter = minimum_prowess_for_knights } }
			}
			AND = {
				prowess >= 12
				$ARMY_OWNER$.culture = {
					has_cultural_parameter = high_prowess_ignores_knight_restrictions
					has_cultural_parameter = minimum_prowess_for_knights
				}
			}
		}
	}
	# Separate custom_description so barred clergy get a clergy-specific reason, not the gender tooltip
	trigger_if = {
		limit = {
			is_clergy = yes
		}
		custom_description = {
			text = "clergy_can_be_combatant"
			object = this
			subject = $ARMY_OWNER$
			OR = {
				rite = { rite_has_parameter = clergy_can_fight }
				AND = {
					has_personal_tenet_flag = clergy_can_fight_personal
					NOT = {
						rite = { rite_has_parameter = pacifist }
					}
				}
				culture = { has_cultural_parameter = culture_clergy_can_fight }
				AND = {
					$ARMY_OWNER$.culture = {
						has_cultural_parameter = high_prowess_ignores_knight_restrictions
					}
					prowess >= 10
				}
			}
		}
	}
}

clergy_can_fight_check_trigger = {
	trigger_if = {
		limit = { is_clergy = yes }
		OR = {
			rite = { rite_has_parameter = clergy_can_fight }
			AND = {
				has_personal_tenet_flag = clergy_can_fight_personal
				NOT = {
					rite = { rite_has_parameter = pacifist }
				}
			}
			culture = { has_cultural_parameter = culture_clergy_can_fight }
		}
	}
}

can_be_clergy_due_to_gender_trigger = {
	OR = {
		AND = {
			rite = { rite_has_parameter = clergy_must_be_female }
			is_female = yes
		}
		AND = {
			rite = { rite_has_parameter = clergy_must_be_male }
			is_male = yes
		}
		rite = { rite_has_parameter = clergy_can_be_either_gender }
	}
}

is_wrong_gender_in_rite_trigger = {
	OR = {
		AND = {
			is_female = yes
			$RITE$ = { rite_has_parameter = male_dominated_law }
		}
		AND = {
			is_male = yes
			$RITE$ = { rite_has_parameter = female_dominated_law }
		}
	}
}

faith_is_aniconic_trigger = {
	OR = {
		faith.religion = religion:islam_religion
		rite = { rite_has_tenet = tenet_aniconism }
	}
}

#Needs CHARACTER and RITE
relation_with_character_is_incestuous_in_rite_trigger = {
	OR = {
		# doctrine_consanguinity_dynastic; not within the same descent group
		AND = {
			$RITE$ = { rite_has_parameter = consanguinity_restricted_dynastic_marriage }
			is_lowborn = no
			$CHARACTER$.dynasty ?= dynasty
		}	
		#doctrine_consanguinity_restricted; absolutely no family business
		AND = {
			$RITE$ = { rite_has_doctrine = doctrine_consanguinity_restricted }
			is_close_or_extended_family_of = $CHARACTER$ #[parents, children, siblings, grandparents, grandchildren, cousins, uncles, aunts, nephews, nieces]
		}
		#doctrine_consanguinity_cousins; the only acceptable incest is with your cousin
		AND = {
			$RITE$ = { rite_has_parameter = consanguinity_cousins_marriage }
			OR = {
	            is_close_family_of = $CHARACTER$ #[parents, children, siblings, grandparents, grandchildren]
	            is_uncle_or_aunt_of = $CHARACTER$
	            is_nibling_of = $CHARACTER$
	        }
		}
		#doctrine_consanguinity_aunt_nephew_and_uncle_niece; extended family is ok
		AND = {
			$RITE$ = { rite_has_parameter = consanguinity_aunt_nephew_and_uncle_niece_marriage }
			is_close_family_of = $CHARACTER$
		}
		#doctrine_consanguinity_unrestricted; all forms of incest is acceptable
	}
}

#Note: only checks from the viewpoint of current scope. Needs CHARACTER
relation_with_character_is_incestuous_in_my_faith_trigger = {
	faith.main_rite = { save_temporary_scope_as = my_rite }
	relation_with_character_is_incestuous_in_rite_trigger = { CHARACTER = $CHARACTER$ RITE = scope:my_rite }
}

relation_with_character_is_incestuous_in_my_rite_trigger = {
	rite = { save_temporary_scope_as = my_rite }
	relation_with_character_is_incestuous_in_rite_trigger = { CHARACTER = $CHARACTER$ RITE = scope:my_rite }
}

relation_with_character_is_incestuous_in_my_or_lieges_rite_trigger = {
	OR = {
		AND = {
			rite = { #My rite doesn't approve
				save_temporary_scope_as = check_rite
			}
			relation_with_character_is_incestuous_in_rite_trigger = { CHARACTER = $CHARACTER$ RITE = scope:check_rite }
		}
		AND = { #Liege's rite doesn't approve
			liege ?= {
				rite = {
					save_temporary_scope_as = check_rite
				}
			}
			relation_with_character_is_incestuous_in_rite_trigger = { CHARACTER = $CHARACTER$ RITE = scope:check_rite }
		}
	}
}

#Needs CHARACTER_1 and CHARACTER_2
rite_allows_marriage_consanguinity_trigger = {
	save_temporary_scope_as = consanguinity_rite

	NOT = {
		$CHARACTER_1$ = {
			relation_with_character_is_incestuous_in_rite_trigger = {
				CHARACTER = $CHARACTER_2$
				RITE = scope:consanguinity_rite
			}
		}
	}
}
relation_between_characters_is_sodomy_in_my_rite_trigger = {
	$CHARACTER_1$ = { is_male = yes }
	$CHARACTER_2$ = { is_male = yes }
	rite = {
		NOT = { rite_has_parameter = homosexuality_accepted }
	}
}

relation_with_character_is_sodomy_in_rite_trigger = {
	is_male = yes
	$CHARACTER$ = { is_male = yes }
	$RITE$ = {
		NOT = { rite_has_parameter = homosexuality_accepted }
	}
}

#Note: only checks from the viewpoint of current scope. Needs CHARACTER
relation_with_character_is_sodomy_by_my_rite_trigger = {
	rite = { save_temporary_scope_as = my_rite }
	relation_with_character_is_sodomy_in_rite_trigger = {
		CHARACTER = $CHARACTER$
		RITE = scope:my_rite
	}
}

relation_with_character_is_sodomy_in_my_or_lieges_rite_trigger = {
	OR = {
		AND = {
			rite = { #My rite doesn't approve
				save_temporary_scope_as = check_rite
			}
			relation_with_character_is_sodomy_in_rite_trigger = { CHARACTER = $CHARACTER$ RITE = scope:check_rite }
		}
		AND = { #Liege's rite doesn't approve
			liege ?= {
				rite = {
					save_temporary_scope_as = check_rite
				}
			}
			relation_with_character_is_sodomy_in_rite_trigger = { CHARACTER = $CHARACTER$ RITE = scope:check_rite }
		}
	}
}

murdering_character_is_kinslaying_in_rite_trigger = {
	OR = {
		is_close_or_extended_family_of = $CHARACTER$
		dynasty = $CHARACTER$.dynasty
	}
	$RITE$ = { NOT = { rite_has_parameter = kinslaying_accepted } }
}

murdering_character_is_kinslaying_in_my_or_same_dynasty_lieges_rite_trigger = {
	save_temporary_scope_as = kinslayer_me
	rite = {
		save_temporary_scope_as = check_rite
	}
	trigger_if = {
		limit = {
			liege ?= { dynasty = scope:kinslayer_me.dynasty }
		}
		liege = {
			rite = {
				save_temporary_scope_as = check_rite_liege
			}
		}
	}
	OR = {
		murdering_character_is_kinslaying_in_rite_trigger = { CHARACTER = $CHARACTER$ RITE = scope:check_rite } #My rite doesn't approve
		AND = { #Liege's rite doesn't approve
			liege ?= { dynasty = scope:kinslayer_me.dynasty }
			murdering_character_is_kinslaying_in_rite_trigger = { CHARACTER = $CHARACTER$ RITE = scope:check_rite_liege }
		}
	}
}

trait_is_criminal_in_rite_trigger = {
	OR = {
		#KINSLAYER
		AND = {
			OR = {
				$TRAIT$ = trait:kinslayer_3
				$TRAIT$ = trait:kinslayer_2
				$TRAIT$ = trait:kinslayer_1
			}
			$RITE$ = { rite_has_parameter = kinslaying_any_dynasty_member_crime }
		}
		AND = {
			OR = {
				$TRAIT$ = trait:kinslayer_3
				$TRAIT$ = trait:kinslayer_2
			}
			$RITE$ = { rite_has_parameter = kinslaying_extended_family_crime }
		}
		AND = {
			$TRAIT$ = trait:kinslayer_3
			$RITE$ = { rite_has_parameter = kinslaying_close_kin_crime }
		}
		#WITCH
		AND = {
			$TRAIT$ = trait:witch
			$RITE$ = { rite_has_parameter = witchcraft_illegal }
		}
		#CANNIBAL
		AND = {
			$TRAIT$ = trait:cannibal
			NOT = {
				$RITE$ = { rite_has_parameter = cannibalism_legal }
			}
		}
		#SODOMITE
		AND = {
			$TRAIT$ = trait:sodomite
			$RITE$ = { rite_has_parameter = homosexuality_illegal }
		}
		#DEVIANT
		AND = {
			$TRAIT$ = trait:deviant
			$RITE$ = { rite_has_parameter = deviancy_illegal }
		}
		#INCEST
		AND = {
			$TRAIT$ = trait:incestuous
			NOT = {
				$RITE$ = { rite_has_parameter = allows_unrestricted_marriage }
			}
		}
		#ADULTERER/FORNICATOR
		AND = {
			OR = {
				$TRAIT$ = trait:adulterer
				$TRAIT$ = trait:fornicator
			}
			OR = {
				AND = {
					$RITE$ = { rite_has_parameter = adultery_female_crime }
					$GENDER_CHARACTER$ = { is_female = yes }
				}
				AND = {
					$RITE$ = { rite_has_parameter = adultery_male_crime }
					$GENDER_CHARACTER$ = { is_male = yes }
				}
			}
		}
		# Devoted is criminal when monasticism is forbidden
		AND = {
			$TRAIT$ = trait:devoted
			$RITE$ = { rite_has_parameter = devoted_trait_criminal }
		}
	}
}

trait_is_shunned_in_rite_trigger = {
	OR = {
		#KINSLAYER
		AND = {
			OR = {
				$TRAIT$ = trait:kinslayer_3
				$TRAIT$ = trait:kinslayer_2
				$TRAIT$ = trait:kinslayer_1
			}
			$RITE$ = { rite_has_parameter = kinslaying_shunned }
		}
		#WITCH
		AND = {
			$TRAIT$ = trait:witch
			$RITE$ = { rite_has_parameter = witchcraft_shunned }
		}
		#SODOMITE
		AND = {
			$TRAIT$ = trait:sodomite
			$RITE$ = { rite_has_parameter = homosexuality_shunned }
		}
		#DEVIANT
		AND = {
			$TRAIT$ = trait:deviant
			$RITE$ = { rite_has_parameter = deviancy_shunned }
		}
		#INCEST
		AND = {
			$TRAIT$ = trait:incestuous
			NOT = {
				$RITE$ = { rite_has_parameter = allows_unrestricted_marriage }
			}
		}
		#ADULTERER/FORNICATOR
		AND = {
			OR = {
				$TRAIT$ = trait:adulterer
				$TRAIT$ = trait:fornicator
			}
			OR = {
				AND = {
					$RITE$ = { rite_has_parameter = adultery_female_shunned }
					$GENDER_CHARACTER$ = { is_female = yes }
				}
				AND = {
					$RITE$ = { rite_has_parameter = adultery_male_shunned }
					$GENDER_CHARACTER$ = { is_male = yes }
				}
			}
		}
	}
}

trait_is_shunned_or_criminal_in_rite_trigger = {
	OR = {
		trait_is_shunned_in_rite_trigger = { TRAIT = $TRAIT$ RITE = $RITE$ GENDER_CHARACTER = $GENDER_CHARACTER$ }
		trait_is_criminal_in_rite_trigger = { TRAIT = $TRAIT$ RITE = $RITE$ GENDER_CHARACTER = $GENDER_CHARACTER$ }
	}
}

trait_is_shunned_or_criminal_in_my_or_lieges_rite_trigger = {
	OR = {
		AND = {
			rite = { #My rite doesn't approve
				save_temporary_scope_as = check_rite
			}
			trait_is_shunned_or_criminal_in_rite_trigger = { TRAIT = $TRAIT$ RITE = scope:check_rite GENDER_CHARACTER = $GENDER_CHARACTER$ }
		}
		AND = { #Liege's rite doesn't approve
			liege ?= {
				rite = {
					save_temporary_scope_as = check_rite
				}
			}
			trait_is_shunned_or_criminal_in_rite_trigger = { TRAIT = $TRAIT$ RITE = scope:check_rite GENDER_CHARACTER = $GENDER_CHARACTER$ }
		}
	}
}

has_any_shunned_or_criminal_trait_in_rite_trigger = {
	$CHARACTER$ = {
		OR = {
			#KINSLAYER
			AND = {
				has_trait = kinslayer_3
				trait_is_shunned_or_criminal_in_rite_trigger = { TRAIT = trait:kinslayer_3 RITE = $RITE$ GENDER_CHARACTER = $CHARACTER$ }
			}
			AND = {
				has_trait = kinslayer_2
				trait_is_shunned_or_criminal_in_rite_trigger = { TRAIT = trait:kinslayer_2 RITE = $RITE$ GENDER_CHARACTER = $CHARACTER$ }
			}
			AND = {
				has_trait = kinslayer_1
				trait_is_shunned_or_criminal_in_rite_trigger = { TRAIT = trait:kinslayer_1 RITE = $RITE$ GENDER_CHARACTER = $CHARACTER$ }
			}
			#WITCH
			AND = {
				has_trait = witch
				trait_is_shunned_or_criminal_in_rite_trigger = { TRAIT = trait:witch RITE = $RITE$ GENDER_CHARACTER = $CHARACTER$ }
			}
			#CANNIBAL
			AND = {
				has_trait = cannibal
				trait_is_shunned_or_criminal_in_rite_trigger = { TRAIT = trait:cannibal RITE = $RITE$ GENDER_CHARACTER = $CHARACTER$ }
			}
			#SODOMITE
			AND = {
				has_trait = sodomite
				trait_is_shunned_or_criminal_in_rite_trigger = { TRAIT = trait:sodomite RITE = $RITE$ GENDER_CHARACTER = $CHARACTER$ }
			}
			#DEVIANT
			AND = {
				has_trait = deviant
				trait_is_shunned_or_criminal_in_rite_trigger = { TRAIT = trait:deviant RITE = $RITE$ GENDER_CHARACTER = $CHARACTER$ }
			}
			AND = {
				has_trait = incestuous
				trait_is_shunned_or_criminal_in_rite_trigger = { TRAIT = trait:incestuous RITE = $RITE$ GENDER_CHARACTER = $CHARACTER$ }
			}
			#ADULTERER/FORNICATOR
			AND = {
				has_trait = adulterer
				trait_is_shunned_or_criminal_in_rite_trigger = { TRAIT = trait:adulterer RITE = $RITE$ GENDER_CHARACTER = $CHARACTER$ }
			}
			AND = {
				has_trait = fornicator
				trait_is_shunned_or_criminal_in_rite_trigger = { TRAIT = trait:fornicator RITE = $RITE$ GENDER_CHARACTER = $CHARACTER$ }
			}
			# Devoted is criminal when monasticism is forbidden
			AND = {
				has_trait = devoted
				$RITE$ = { rite_has_parameter = devoted_trait_criminal }
			}
		}
	}
}

has_any_criminal_trait_in_rite_trigger = {
	$CHARACTER$ = {
		OR = {
			#KINSLAYER
			AND = {
				has_trait = kinslayer_3
				trait_is_criminal_in_rite_trigger = { TRAIT = trait:kinslayer_3 RITE = $RITE$ GENDER_CHARACTER = $CHARACTER$ }
			}
			AND = {
				has_trait = kinslayer_2
				trait_is_criminal_in_rite_trigger = { TRAIT = trait:kinslayer_2 RITE = $RITE$ GENDER_CHARACTER = $CHARACTER$ }
			}
			AND = {
				has_trait = kinslayer_1
				trait_is_criminal_in_rite_trigger = { TRAIT = trait:kinslayer_1 RITE = $RITE$ GENDER_CHARACTER = $CHARACTER$ }
			}
			#WITCH
			AND = {
				has_trait = witch
				trait_is_criminal_in_rite_trigger = { TRAIT = trait:witch RITE = $RITE$ GENDER_CHARACTER = $CHARACTER$ }
			}
			#CANNIBAL
			AND = {
				has_trait = cannibal
				trait_is_criminal_in_rite_trigger = { TRAIT = trait:cannibal RITE = $RITE$ GENDER_CHARACTER = $CHARACTER$ }
			}
			#SODOMITE
			AND = {
				has_trait = sodomite
				trait_is_criminal_in_rite_trigger = { TRAIT = trait:sodomite RITE = $RITE$ GENDER_CHARACTER = $CHARACTER$ }
			}
			#DEVIANT
			AND = {
				has_trait = deviant
				trait_is_criminal_in_rite_trigger = { TRAIT = trait:deviant RITE = $RITE$ GENDER_CHARACTER = $CHARACTER$ }
			}
			AND = {
				has_trait = incestuous
				trait_is_criminal_in_rite_trigger = { TRAIT = trait:incestuous RITE = $RITE$ GENDER_CHARACTER = $CHARACTER$ }
			}
			#ADULTERER/FORNICATOR
			AND = {
				has_trait = adulterer
				trait_is_criminal_in_rite_trigger = { TRAIT = trait:adulterer RITE = $RITE$ GENDER_CHARACTER = $CHARACTER$ }
			}
			AND = {
				has_trait = fornicator
				trait_is_criminal_in_rite_trigger = { TRAIT = trait:fornicator RITE = $RITE$ GENDER_CHARACTER = $CHARACTER$ }
			}
			# Devoted is criminal when monasticism is forbidden
			AND = {
				has_trait = devoted
				$RITE$ = { rite_has_parameter = devoted_trait_criminal }
			}
		}
	}
}

has_any_shunned_trait_in_rite_trigger = {
	$CHARACTER$ = {
		OR = {
			#KINSLAYER
			AND = {
				has_trait = kinslayer_3
				trait_is_shunned_in_rite_trigger = { TRAIT = trait:kinslayer_3 RITE = $RITE$ GENDER_CHARACTER = $CHARACTER$ }
			}
			AND = {
				has_trait = kinslayer_2
				trait_is_shunned_in_rite_trigger = { TRAIT = trait:kinslayer_2 RITE = $RITE$ GENDER_CHARACTER = $CHARACTER$ }
			}
			AND = {
				has_trait = kinslayer_1
				trait_is_shunned_in_rite_trigger = { TRAIT = trait:kinslayer_1 RITE = $RITE$ GENDER_CHARACTER = $CHARACTER$ }
			}
			#WITCH
			AND = {
				has_trait = witch
				trait_is_shunned_in_rite_trigger = { TRAIT = trait:witch RITE = $RITE$ GENDER_CHARACTER = $CHARACTER$ }
			}
			#CANNIBAL
			AND = {
				has_trait = cannibal
				trait_is_shunned_in_rite_trigger = { TRAIT = trait:cannibal RITE = $RITE$ GENDER_CHARACTER = $CHARACTER$ }
			}
			#SODOMITE
			AND = {
				has_trait = sodomite
				trait_is_shunned_in_rite_trigger = { TRAIT = trait:sodomite RITE = $RITE$ GENDER_CHARACTER = $CHARACTER$ }
			}
			#DEVIANT
			AND = {
				has_trait = deviant
				trait_is_shunned_in_rite_trigger = { TRAIT = trait:deviant RITE = $RITE$ GENDER_CHARACTER = $CHARACTER$ }
			}
			AND = {
				has_trait = incestuous
				trait_is_shunned_in_rite_trigger = { TRAIT = trait:incestuous RITE = $RITE$ GENDER_CHARACTER = $CHARACTER$ }
			}
			#ADULTERER/FORNICATOR
			AND = {
				has_trait = adulterer
				trait_is_shunned_in_rite_trigger = { TRAIT = trait:adulterer RITE = $RITE$ GENDER_CHARACTER = $CHARACTER$ }
			}
			AND = {
				has_trait = fornicator
				trait_is_shunned_in_rite_trigger = { TRAIT = trait:fornicator RITE = $RITE$ GENDER_CHARACTER = $CHARACTER$ }
			}
		}
	}
}


has_negative_attitude_towards_trait_trigger = {
	NOR = {
		has_trait = $TRAIT$
		#INCESTUOUS
		AND = {
			$TRAIT$ = trait:incestuous
			any_secret = { type = secret_incest }
		}
		#WITCH
		AND = {
			$TRAIT$ = trait:witch
			any_secret = { type = secret_witch }
		}
		#CANNIBAL
		AND = {
			$TRAIT$ = trait:cannibal
			any_secret = { type = secret_cannibal }
		}
		#SODOMITE
		AND = {
			$TRAIT$ = trait:sodomite
			OR = {
				has_sexuality = homosexual
				has_sexuality = bisexual
			}
			any_secret = {
				type = secret_homosexual
			}
		}
		#ADULTERER
		AND = {
			$TRAIT$ = trait:adulterer
			OR = {
				has_trait = lustful
				AND = {
					is_married = yes
					any_relation = { type = lover NOT = { is_spouse_of = prev } }
				}
				any_relation = {
					type = lover
					is_married = yes
					NOT = { is_spouse_of = prev }
				}
			}
		}
		#FORNICATOR
		AND = {
			$TRAIT$ = trait:fornicator
			OR = {
				has_trait = lustful
				any_relation = { type = lover always = yes }
			}
		}
	}

	rite = { save_temporary_scope_as = my_rite }
	OR = {
		trait_is_shunned_in_rite_trigger = { TRAIT = $TRAIT$ RITE = scope:my_rite GENDER_CHARACTER = $GENDER_CHARACTER$ }
		trait_is_criminal_in_rite_trigger = { TRAIT = $TRAIT$ RITE = scope:my_rite GENDER_CHARACTER = $GENDER_CHARACTER$ }
	}
}

has_followers_trigger = {
	OR = {
		num_character_followers >= 1
		num_county_followers >= 1
	}
}

secret_is_blackmailable_trigger = {
	OR = {
		secret_is_blackmailable_strong_hook_trigger = { TARGET = $TARGET$ }
		secret_is_blackmailable_weak_hook_trigger = { TARGET = $TARGET$ }
	}
}


###################
# Heresy Triggers #
###################

#Christian Heresy Groups
faiths_are_in_western_christianity_group = {
	OR = {
		$FAITH_1$ = faith:catholic
		$FAITH_1$ = faith:cathar
		$FAITH_1$ = faith:waldensian
		$FAITH_1$ = faith:lollard
	}
	OR = {
		$FAITH_2$ = faith:catholic
		$FAITH_2$ = faith:cathar
		$FAITH_2$ = faith:waldensian
		$FAITH_2$ = faith:lollard
		$FAITH_2$ = faith:gnostic_faith
	}
}

faiths_are_in_orthodox_christianity_group = {
	OR = {
		$FAITH_1$ = faith:orthodox
		$FAITH_1$ = faith:iconoclast
		$FAITH_1$ = faith:bogomilist
		$FAITH_1$ = faith:paulician
	}
	OR = {
		$FAITH_2$ = faith:orthodox
		$FAITH_2$ = faith:iconoclast
		$FAITH_2$ = faith:bogomilist
		$FAITH_2$ = faith:paulician
		$FAITH_2$ = faith:bosnian_church
		$FAITH_2$ = faith:gnostic_faith
	}
}

faiths_are_in_eastern_christianity_group = {
	OR = {
		$FAITH_1$ = faith:miaphysitism
		$FAITH_1$ = faith:armenian_apostolic
		$FAITH_1$ = faith:nestorian
		$FAITH_1$ = faith:messalian
		$FAITH_1$ = faith:paulician
	}
	OR = {
		$FAITH_2$ = faith:miaphysitism
		$FAITH_2$ = faith:armenian_apostolic
		$FAITH_2$ = faith:nestorian
		$FAITH_2$ = faith:messalian
		$FAITH_2$ = faith:paulician
		$FAITH_2$ = faith:mandaean_faith
	}
}

is_non_chalcedonianism_christian_faith = {
	OR = {
		this = faith:nestorian
		this = faith:miaphysitism
		this = faith:armenian_apostolic
	}
}

faiths_are_shia_zandaqa_sub_group = {
	OR = {
		$FAITH$ = faith:quranist
		$FAITH$ = faith:druze
	}
}

faiths_are_in_sunni_islam_group = {
	$RITE_1$ = {
		rite_has_doctrine = muhammad_succession_sunni_doctrine
	}
	OR = {
		$RITE_2$ = {
			OR = {
				rite_has_doctrine = muhammad_succession_sunni_doctrine
				rite_has_doctrine = muhammad_succession_muhakkima_doctrine
			}
		}
		$FAITH_2$ = faith:mandaean_faith
		$FAITH_2$ = faith:manichaean_faith
		$FAITH_2$ = faith:quranist
	}
}

faiths_are_in_shia_islam_group = {
	OR = {
		$RITE_1$ = { rite_has_doctrine = muhammad_succession_shia_doctrine }
		faiths_are_shia_zandaqa_sub_group = { FAITH = $FAITH_1$ }
	}
	OR = {
		$RITE_2$ = {
			OR = {
				rite_has_doctrine = muhammad_succession_shia_doctrine
				rite_has_doctrine = muhammad_succession_muhakkima_doctrine
			}
		}
		faiths_are_shia_zandaqa_sub_group = { FAITH = $FAITH_2$ }
		$FAITH_2$ = faith:gnostic_faith
		$FAITH_2$ = faith:mandaean_faith
	}
}

faiths_are_in_muhakkima_islam_group = {
	$RITE_1$ = {
		rite_has_doctrine = muhammad_succession_muhakkima_doctrine
	}
	OR = {
		$RITE_2$ = { rite_has_doctrine = muhammad_succession_muhakkima_doctrine }
		$FAITH_2$ = faith:manichaean_faith
		$FAITH_2$ = faith:gnostic_faith
	}
}

faiths_are_eastern_zoroastrian = { #FP3 update - so that Armenian faith (Arewordik) don't appear as a heresy in Sogdia
	OR = {
		$FAITH_1$ = faith:mazdayasna
		$FAITH_1$ = faith:khurmazta
		$FAITH_1$ = faith:gayomarthianism
		$FAITH_2$ = faith:zurvanism
		$FAITH_2$ = faith:mazdakism
		$FAITH_2$ = faith:khurramism
	}
	OR = {
		$FAITH_1$ = faith:mazdayasna
		$FAITH_1$ = faith:khurmazta
		$FAITH_1$ = faith:gayomarthianism
		$FAITH_2$ = faith:zurvanism
		$FAITH_2$ = faith:mazdakism
		$FAITH_2$ = faith:khurramism
	}
}

faiths_are_western_zoroastrian = { #FP3 update - so that Sogdian faith (Khurmazta) don't appear as a heresy in Armenia
	OR = {
		$FAITH_1$ = faith:mazdayasna
		$FAITH_1$ = faith:gayomarthianism
		$FAITH_2$ = faith:zurvanism
		$FAITH_2$ = faith:mazdakism
		$FAITH_2$ = faith:khurramism
		$FAITH_2$ = faith:urartuism
	}
	OR = {
		$FAITH_1$ = faith:mazdayasna
		$FAITH_1$ = faith:gayomarthianism
		$FAITH_2$ = faith:zurvanism
		$FAITH_2$ = faith:mazdakism
		$FAITH_2$ = faith:khurramism
		$FAITH_2$ = faith:urartuism
	}
}

refusing_conversion_is_crime_trigger = {
	OR = {
		has_title = title:e_minister_of_rites
		rite = {
			trigger_if = { # Only apply imprisonment reason if actor's rite is not the state rite
				limit = {
					$CHARACTER$ = {
						top_liege = { government_allows = state_faith }
						rite = $CHARACTER$.top_liege.primary_title.state_rite
					}
				}
				always = no
			}
			OR = {
				rite_religion_tag = christianity_religion
				rite_religion_tag = islam_religion
				rite_religion_tag = judaism_religion
				rite_religion_tag = zoroastrianism_religion
			}
			NOT = {
				rite_hostility_level = {
					target = $CHARACTER$.rite
					value <= faith_astray_level
				}
			}
		}
	}
}

character_can_create_holy_order_basic_trigger = {
	NOR = {
		faith = {
			has_doctrine_parameter = immaterial_harmony_no_holy_orders
		}
		faith = {
			any_faith_holy_order = {
				#Can be monastic patron and found military order
				leader ?= {
					government_has_flag = government_is_military_holy_order
				}
				holy_order_patron = root
				save_temporary_scope_as = order
			}
		}
	}
}

# Rite scope: is this rite hostile enough towards RITE to holy war against it?
is_hostile_enough_for_holy_war_trigger = {
	rite_hostility_level = {
		target = $RITE$
		value >= religious_cb_enabled_hostility_level
	}
}

# Character scope: may this attacker press a religious war against TARGET?
is_valid_religious_war_target_trigger = {
	OR = {
		rite = { is_hostile_enough_for_holy_war_trigger = { RITE = $TARGET$.rite } }
		AND = {
			rite = { rite_has_parameter = literalism_holy_war_cb_active }
			religion = $TARGET$.religion
			NOT = { $TARGET$.rite = { rite_has_tenet = tenet_literalism } }
		}
	}
}

barony_is_valid_for_holy_order_lease_trigger = {
	title_province = {
		OR = {
			has_holding_type = castle_holding
			has_holding_type = city_holding
		}
	}
	trigger_if = {
		limit = {
			holder.primary_title.tier != tier_barony
		}
		can_be_leased_out = yes
	}
	trigger_if = {
		limit = {
			NOT = { holder = $CHARACTER$ }
		}
		holder.primary_title.tier = tier_barony
	}
	NOT = {
		is_leased_out = yes
	}
}
barony_is_valid_for_monastic_order_lease_trigger = {
	title_province = {
		has_holding_type = church_holding
	}
	trigger_if = {
		limit = {
			holder.primary_title.tier != tier_barony
		}
		can_be_leased_out = yes
	}
	trigger_if = {
		limit = {
			NOT = { holder = $CHARACTER$ }
		}
		holder.primary_title.tier = tier_barony
	}
	OR = {
		NOT = {
			is_leased_out = yes
		}
		#Theocratic lessee
		lessee = {
			NOT = {
				government_has_flag = government_is_monastic_holy_order
			}
		}
	}
}

barony_is_valid_for_holy_order_lease_cancellation_trigger = {
	is_under_holy_order_lease = yes
	has_revokable_lease = yes
	lessee = {
		NOT = {
			has_strong_hook = prev.holder
		}
	}
	trigger_if = {
		limit = { lessee.faith != $ACTOR$.faith }
		# can not revoke holy order under religious protection
		save_temporary_scope_as = valid_baron
		holder = {
			NOT = {
				any_liege_or_above = {
					NOT = {
						this = $ACTOR$
					}
					is_vassal_or_below_of = $ACTOR$
					faith = scope:valid_baron.lessee.faith
					vassal_contract_has_flag = religiously_protected
				}
			}
		}
	}
}

barony_is_valid_for_monastic_lease_trigger = {
	county = {
		any_county_province = {
			has_holding = no
			has_ongoing_construction = no
		}
		holder = $CHARACTER$
	}
}
county_is_valid_for_monastic_lease_trigger = {
	any_county_province = {
		has_holding = no
		has_ongoing_construction = no
	}
	holder = $CHARACTER$
}

barony_is_valid_to_be_transferred_by_monastic_movement_trigger = {
	is_under_holy_order_lease = yes
	lessee ?= {
		faith = $CHARACTER$.faith
		government_has_flag = government_is_monastic_holy_order
		holy_order ?= {
			NOT = { holy_order_patron ?= root }
		}
	}
	NOT = {
		county = lessee.capital_county
	}
}

religion_has_angels_trigger = {
	OR = {
		religion = religion:christianity_religion
		religion = religion:islam_religion
		religion = religion:zoroastrianism_religion
		religion = religion:dualism_religion
		religion = religion:judaism_religion
		religion = religion:yazidi_religion
	}
}

religion_has_circumcision_trigger = {
	OR = {
		religion = religion:islam_religion
		religion = religion:judaism_religion
	}
}

is_heretic_trigger = {
	$WHO$.faith.religion = $TARGET$.faith.religion
	$WHO$.faith = {
		faith_hostility_level = {
			target = $TARGET$.faith
			value >= religious_cb_enabled_hostility_level
		}
	}
}

is_heathen_trigger = {
	NOT = { $WHO$.faith.religion = $TARGET$.faith.religion }
	$TARGET$.faith = {
		has_doctrine = pagan_hostility_doctrine
	}
	$WHO$.faith = {
		faith_hostility_level = {
			target = $TARGET$.faith
			value >= religious_cb_enabled_hostility_level
		}
	}
}

is_infidel_trigger = {
	NOT = { $WHO$.faith.religion = $TARGET$.faith.religion }
	$TARGET$.faith = {
		NOT = { has_doctrine = pagan_hostility_doctrine }
	}
	$WHO$.faith = {
		faith_hostility_level = {
			target = $TARGET$.faith
			value >= religious_cb_enabled_hostility_level
		}
	}
}

valid_demand_conversion_conditions_trigger = {
	scope:recipient = {
		NOR = {
			has_strong_hook = scope:puppet_or_actor
			has_trait = devoted
			has_trait = order_member
			is_imprisoned_by = scope:puppet_or_actor
			is_at_war_with = scope:puppet_or_actor
		}
	}
	scope:puppet_or_actor = {
		trigger_if = {
			limit = {
				government_has_flag = government_is_landless_adventurer
				scope:recipient = { is_courtier_of = scope:puppet_or_actor }
			}
			custom_tooltip = {
				text = valid_demand_conversion_conditions_trigger.tt.domicile_requires_shrine
				domicile = { has_domicile_parameter = camp_enable_conversion }
			}
		}
		custom_tooltip = {
			text = demand_conversion_nomadic_zealous_tt
			NAND = {
				has_trait = nomadic_philosophy
				has_trait = zealous
			}
		}
	}

	custom_description = {
		text = "is_head_of_religion"
		subject = scope:recipient
		scope:recipient.faith.religious_head != scope:recipient
	}
	custom_description = {
		text = "is_protected_via_contract"
		subject = scope:recipient
		# Vassal Contract forbids meddling by liege
		NAND = {
			exists = scope:recipient.liege
			scope:recipient.liege = scope:puppet_or_actor
			scope:recipient = {
				is_ruler = yes
				vassal_contract_has_flag = religiously_protected
			}
		}
	}
	trigger_if = {
		limit = {
			scope:recipient = {
				AND = {
					has_variable = cannot_be_converted_by_value
					var:cannot_be_converted_by_value = scope:puppet_or_actor
				}
			}
		}
		custom_tooltip = {
			text = promised_to_not_convert_character
			scope:recipient = {
				NOR = {
					has_variable = cannot_be_converted_by_value
					var:cannot_be_converted_by_value = scope:puppet_or_actor
				}
			}
		}
	}
	custom_tooltip = {
		text = cannot_take_overt_hostile_actions_against_diarch.tt
		NOT = { scope:recipient ?= scope:puppet_or_actor.diarch }
	}
}

valid_ask_for_conversion_conditions_trigger = { # Deliberate variant of the above, so you can ask your diarch nicely to convert if you made a new faith
	scope:recipient = {
		NOR = {
			has_strong_hook = scope:actor
			has_trait = devoted
			has_trait = order_member
			is_imprisoned_by = scope:actor
			is_at_war_with = scope:actor
		}
	}
	scope:actor = {
		trigger_if = {
			limit = {
				government_has_flag = government_is_landless_adventurer
				scope:recipient = { is_courtier_of = scope:actor }
			}
			custom_tooltip = {
				text = valid_demand_conversion_conditions_trigger.tt.domicile_requires_shrine
				domicile = { has_domicile_parameter = camp_enable_conversion }
			}
		}
		trigger_if = {
			limit = { has_trait = nomadic_philosophy }
			has_trait = zealous
		}
	}

	custom_description = {
		text = "is_head_of_religion"
		subject = scope:recipient
		scope:recipient.faith.religious_head != scope:recipient
	}
	custom_description = {
		text = "is_protected_via_contract"
		subject = scope:recipient
		# Vassal Contract forbids meddling by liege
		NAND = {
			exists = scope:recipient.liege
			scope:recipient.liege = scope:actor
			scope:recipient = {
				is_ruler = yes
				vassal_contract_has_flag = religiously_protected
			}
		}
	}
	trigger_if = {
		limit = {
			scope:recipient = {
				AND = {
					has_variable = cannot_be_converted_by_value
					var:cannot_be_converted_by_value = scope:actor
				}
			}
		}
		custom_tooltip = {
			text = promised_to_not_convert_character
			scope:recipient = {
				NOR = {
					has_variable = cannot_be_converted_by_value
					var:cannot_be_converted_by_value = scope:actor
				}
			}
		}
	}
}

highgod_is_passive_trigger = {
	OR = {
		religion_tag = buddhism_religion
		religion_tag = jainism_religion
		religion_tag = taoism_religion
		religion_tag = west_african_roog_religion
		religion_tag = zunism_religion
	}
}

highgod_is_active_trigger = {
	highgod_is_passive_trigger = no
}


fertilitygod_is_active_trigger = {
	highgod_is_active_trigger = yes
}


###REINCARNATION###
can_become_reincarnation_trigger = {
	save_temporary_scope_as = reincarnated_child
	rite = {
		rite_has_tenet = tenet_reincarnation
	}
	any_parent = {
		is_playable_character = yes
		faith = scope:reincarnated_child.faith
	}
}

can_reincarnate_trigger = {
	is_alive = no
	OR = {
		has_trait = temperate
		has_trait = greedy
		has_trait = generous
		has_trait = diligent
		has_trait = calm
		has_trait = arrogant
		has_trait = humble
		has_trait = deceitful
		has_trait = honest
		has_trait = brave
		has_trait = gregarious
		has_trait = ambitious
		has_trait = just
		has_trait = zealous
		has_trait = compassionate
		has_trait = stubborn
		has_trait = forgiving
		has_trait = lunatic
		has_trait = dull
		has_trait = intellect_bad
		has_trait = shrewd
		has_trait = intellect_good
		has_trait = strong
		has_trait = physique_good
	}
}

is_reincarnation_trigger = {
	can_become_reincarnation_trigger = yes
	has_variable = reincarnation_of
}

# Used in faith scope, COUNT is number of faiths to at least have and CHARACTER is who must own them
num_realm_holy_sites_faithful_holders = {
	$CHARACTER$ = { save_temporary_scope_as = root_scope }
	trigger_if = {
		limit = {
			exists = $CHARACTER$.confederation
		}
		custom_description = {
			text = direct_realm_holy_sites_held_by_faithful_confederation
			subject = $CHARACTER$
			object = this
			value = 1
			any_holy_site_barony = {
				county = {
					save_temporary_scope_as = current_holy_site
					is_holy_site_controlled_by = $CHARACTER$
					holder.faith = $CHARACTER$.faith
				}
			}
		}
	}
	custom_description = {
		text = number_realm_holy_sites_held_by_faithful
		subject = $CHARACTER$
		object = this
		value = $COUNT$
		any_holy_site_barony = {
			count >= $COUNT$
			county = {
				save_temporary_scope_as = current_holy_site
				OR = {
					is_holy_site_controlled_by = $CHARACTER$
					$CHARACTER$.confederation ?= {
						is_house_based = no # any_confederation_member is not performant for house blocs
						any_confederation_member = {
							scope:current_holy_site = {
								is_holy_site_controlled_by = prev
							}
						}
					}
				}
				holder.faith = $CHARACTER$.faith
			}
		}
	}
}

### Head of Faith
can_create_temporal_head_of_faith_title_trigger = {
	trigger_if = {
		limit = {
			this = faith:christian_faith
			exists = situation:the_christian_church
		}
		custom_tooltip = {
			text = pam_great_schism_decision_taken
			has_global_variable = pam_great_schism_decision_taken
		}
	}
	num_realm_holy_sites_faithful_holders = {
		COUNT = holy_sites_to_create_temporal_head_of_faith
		CHARACTER = root
	}
	root.piety_level >= high_piety_level
	trigger_if = {
		limit = { root = { top_liege != this } }
		custom_description = {
			text = cannot_create_hof_title_at_or_above_liege_tier
			root.liege.primary_title.tier > tier_duchy
		}
	}
	root = {
		trigger_if = {
			limit = { faith.religious_head ?= this }
			NOT = {
				custom_tooltip = {
					text = empire_faith_gate_hof_temporal_is_hof
					faith.religious_head ?= this
				}
			}
		}
	}
}

can_create_spiritual_head_of_faith_title_trigger = {
	trigger_if = {
		limit = {
			this = faith:christian_faith
			exists = situation:the_christian_church
		}
		custom_tooltip = {
			text = pam_great_schism_decision_taken
			has_global_variable = pam_great_schism_decision_taken
		}
	}
	num_realm_holy_sites_faithful_holders = {
		COUNT = holy_sites_to_create_spiritual_head_of_faith
		CHARACTER = root
	}
	# Non-mainline rites need one more level of devotion than the mainline rite
	trigger_if = {
		limit = {
			root = { NOT = { rite = faith.main_rite } }
		}
		root.piety_level >= high_piety_level
	}
	trigger_else = {
		root.piety_level >= medium_piety_level
	}
	trigger_if = {
		limit = { has_doctrine_parameter = block_from_create_hof_parameter }
		NOT = { has_doctrine_parameter = block_from_create_hof_parameter }
	}
	root = {
		trigger_if = {
			limit = { faith.religious_head ?= this }
			NOT = {
				custom_tooltip = {
					text = can_create_spiritual_hof_title_trigger_is_hof_tt
					faith.religious_head ?= this
				}
			}
		}
	}
}

# FAITH = The faith we are trying to make the head of faith title for
# this = Person trying to create the title
can_create_head_of_faith_title_trigger = {
	$FAITH$ = {
		trigger_if = {
			limit = {
				has_doctrine_parameter = spiritual_head_of_faith
			}
			can_create_spiritual_head_of_faith_title_trigger = yes
		}
		trigger_else_if = {
			limit = {
				has_doctrine_parameter = temporal_head_of_faith
			}
			can_create_temporal_head_of_faith_title_trigger = yes
		}
		trigger_else = {
			# We shouldn't hit this point, but if we do use the following as error messages.
			has_doctrine_parameter = spiritual_head_of_faith
			has_doctrine_parameter = temporal_head_of_faith
		}
	}
}

can_perform_the_hajj_trigger = {
	faith.religion = religion:islam_religion
	rite = { rite_has_parameter = can_go_on_pilgrimage }
}

shared_faith_or_hof_trigger = {
	OR = {
		$ACTOR$.faith = $RECIPIENT$.faith
		AND = {
			exists = $ACTOR$.faith.religious_head
			exists = $RECIPIENT$.faith.religious_head
			$ACTOR$.faith.religious_head = $RECIPIENT$.faith.religious_head
		}
	}
}


###RELIGIOUS INTERACTIONS###
#Triggers that applies to both Monastery or Military Order requirements
can_take_religious_vows_trigger = {
	can_take_religious_vows_disregard_marriage_trigger = yes

	#Do they have the "wrong" marriage type?
	NOR = {
		custom_description = {
			text = is_married_matrilineally
			subject = scope:recipient
			any_spouse = {
				is_female = yes
				matrilinear_marriage = yes
			}
		}
		custom_description = {
			text = is_married_patrilineally
			subject = scope:recipient
			any_spouse = {
				is_male = yes
				patrilinear_marriage = yes
			}
		}
		custom_description = {
			text = matrilinear_betrothal
			subject = scope:recipient
			betrothed ?= {
				is_female = yes
				matrilinear_betrothal = yes
			}
		}
		custom_description = {
			text = patrilinear_betrothal
			subject = scope:recipient
			betrothed ?= {
				is_male = yes
				patrilinear_betrothal = yes
			}
		}
	}
	bp2_valid_for_standard_interactions_trigger = yes
}

can_take_religious_vows_disregard_marriage_trigger = {
	is_available_ai = yes
	faith = scope:puppet_or_actor.faith
	is_ruler = no
	NOT = { has_trait = excommunicated }
	NOT = { has_character_flag = holy_order_member_requested_return_home }
}

does_religion_exist_in_world_region_trigger = { # The most efficient way I could think of to essentially do diplomatic range triggers on religions
	trigger_if = {
		limit = { location = { geographical_region = world_europe } } # Even though europe has many sub regions, it's overall size is small so no need to sub-divide!
		any_county_in_region = {
			region = world_europe
			faith.religion = $RELIGION$
		}
	}
	trigger_else_if = {
		limit = { location = { geographical_region = world_asia_minor } } # Maybe this should be grouped with both the one above and the one below...
		any_county_in_region = {
			region = world_asia_minor
			faith.religion = $RELIGION$
		}
	}
	trigger_else_if = {
		limit = { location = { geographical_region = world_middle_east } }
		any_county_in_region = {
			region = world_middle_east
			faith.religion = $RELIGION$
		}
	}
	trigger_else_if = {
		limit = { location = { geographical_region = world_india } }
		any_county_in_region = {
			region = world_india
			faith.religion = $RELIGION$
		}
	}
	trigger_else_if = {
		limit = { location = { geographical_region = world_africa } }
		any_county_in_region = {
			region = world_africa
			faith.religion = $RELIGION$
		}
	}
	trigger_else_if = {
		limit = { location = { geographical_region = world_steppe } }
		any_county_in_region = {
			region = world_steppe
			faith.religion = $RELIGION$
		}
	}
	trigger_else_if = {
		limit = { location = { geographical_region = world_asia } }
		any_county_in_region = {
			region = world_asia
			faith.religion = $RELIGION$
		}
	}
	trigger_else_if = {
		limit = { location = { geographical_region = world_asia_southeast } }
		any_county_in_region = {
			region = world_asia_southeast
			faith.religion = $RELIGION$
		}
	}
	trigger_else_if = {
		limit = { location = { geographical_region = world_tibet } }
		any_county_in_region = {
			region = world_tibet
			faith.religion = $RELIGION$
		}
	}
	trigger_else = { always = no } # This should always go at the end of this scripted trigger
}

### Military OrderS ###
is_military_order_trigger = {
	leader ?= {
		government_has_flag = government_is_military_holy_order
	}
}
is_monastic_order_trigger = {
	leader ?= {
		government_has_flag = government_is_monastic_holy_order
	}
}

holy_order_1000_holy_order_trigger = {
	title = {
		has_none_of_variables = {
			name = received_new_land
			name = discarded_for_being_too_big
		}
	}
}

holy_order_1000_target_barony_trigger = {
	tier = tier_barony
	barony_is_valid_for_holy_order_lease_trigger = { CHARACTER = $CHARACTER$ }
	#Don't grab something that's held by a vassal player of the one receiving the event.
	trigger_if = {
		limit = {
			NOT = { holder = $CHARACTER$ }
		}
		holder = { is_ai = yes }
	}
}
holy_order_1010_target_monastic_barony_trigger = {
	tier = tier_barony
	barony_is_valid_for_monastic_order_lease_trigger = { CHARACTER = $CHARACTER$ }
	#Don't grab something that's held by a vassal player of the one receiving the event.
	trigger_if = {
		limit = {
			NOT = { holder = $CHARACTER$ }
		}
		holder = { is_ai = yes }
	}
}

holy_order_1000_request_target_trigger = {
	highest_held_title_tier >= tier_duchy
	is_landed = yes
	faith = root
	is_available = yes
	has_none_of_variables = {
		name = holy_order_recently_requested_land
		name = holy_order_recently_received_land
	}
	save_temporary_scope_as = ruler
	any_sub_realm_barony = {
		holy_order_1000_target_barony_trigger = { CHARACTER = scope:ruler }
	}
}
holy_order_1010_request_target_trigger = {
	highest_held_title_tier >= tier_duchy
	is_landed = yes
	#faith = root
	is_available = yes
	has_none_of_variables = {
		name = monastic_order_recently_requested_land
		name = monastic_order_recently_received_land
	}
	save_temporary_scope_as = ruler
	any_sub_realm_barony = {
		holy_order_1010_target_monastic_barony_trigger = { CHARACTER = scope:ruler }
	}
}

faith_dominant_gender_male_or_equal = {
	rite = {
		OR = {
			rite_has_parameter = male_dominated_law
			rite_has_parameter = gender_equal_law
		}
	}
}

faith_dominant_gender_female_or_equal = {
	rite = {
		OR = {
			rite_has_parameter = female_dominated_law
			rite_has_parameter = gender_equal_law
		}
	}
}

is_theological_character_trigger = {
	OR = {
		has_trait = theologian
		has_trait = devoted
		has_trait = order_member
		AND = {
			is_playable_character = yes
			government_has_flag = government_is_theocracy
		}

	}
}

holds_religious_office_trigger = {
	OR = {
		government_has_flag = government_is_ecclesiastical
		exists = clerical_elector_title
		AND = {
			religion = religion:christianity_religion
			religious_head_or_challenger ?= this
		}
	}
}

would_be_sinful_adulterer_trigger = {
	is_married = yes
	trigger_if = {
		limit = { is_male = yes }
		NOT = {
			rite = { rite_has_doctrine = doctrine_adultery_men_accepted }
		}
	}
	trigger_else = {
		NOT = {
			rite = { rite_has_doctrine = doctrine_adultery_women_accepted }
		}
	}
}

has_tolerant_faith_or_culture_trigger = {
	OR = {
		rite = { rite_has_doctrine = doctrine_pluralism_pluralistic }
		culture = { has_cultural_parameter = less_likely_to_force_conversion }
		culture = { has_cultural_tradition = tradition_religion_blending }
		has_trait = nomadic_philosophy
	}
}

is_open_to_inviting_other_faiths_trigger = {
	OR = {
		rite = { rite_has_tenet = tenet_adaptive }
		faith = { has_doctrine = unreformed_faith_doctrine }
		rite = { rite_has_doctrine = doctrine_pluralism_pluralistic }
		culture = { has_cultural_tradition = tradition_religion_blending }
		culture = { has_cultural_tradition = tradition_tgp_religious_hospitality }
	}
}

faith_is_open_minded_trigger = {
	OR = {
		rite_has_tenet = tenet_adaptive
		rite_has_doctrine = doctrine_pluralism_pluralistic
	}
}

is_mainstream_jewish_faith = {
	religion = religion:judaism_religion
	NOT = {
		this = faith:samaritan
		this = faith:haymanot
		this = faith:malabarism
		this = faith:kabarism
	}
}

is_unprotected_hostile_faith = { # Checks if the faith is at least hostile but not protected by a contract, used in a county scope
	faith = {
		faith_hostility_level = {
			target = prev.holder.top_liege.faith
			value >= 2
		}
	}
	holder = {
		NOT = { vassal_contract_has_flag = religiously_protected }
	}
	trigger_if = { # Does anyone in the hierarchy have religious protection?
		limit = {
			holder = {
				any_liege_or_above = {
					faith = prev.faith
				}
			}
		}
		holder = {
			any_liege_or_above = {
				NOT = { vassal_contract_has_flag = religiously_protected }
			}
		}
	}
}

### SYNCRETIC TRIGGERS ###

islam_or_syncretic_with_islam_trigger = {
	$CHARACTER$ = {
		OR = {
			faith.religion = religion:islam_religion
			rite = { rite_has_parameter = islamic_syncretic_actor }
		}
	}
}

judaism_or_syncretic_with_judaism_trigger = {
	$CHARACTER$ = {
		OR = {
			faith.religion = religion:judaism_religion
			rite = { rite_has_parameter = jewish_syncretic_actor }
		}
	}
}

christianity_or_syncretic_with_christianity_trigger = {
	$CHARACTER$ = {
		OR = {
			faith.religion = religion:christianity_religion
			rite = { rite_has_parameter = christian_syncretic_actor }
		}
	}
}

unreformed_or_syncretic_with_unreformed_trigger = {
	$CHARACTER$ = {
		OR = {
			faith = { has_doctrine_parameter = unreformed }
			rite = { rite_has_parameter = unreformed_syncretic_actor }
		}
	}
}

zoroastrian_or_syncretic_with_eastern_trigger = {
	$CHARACTER$ = {
		OR = {
			faith.religion = religion:zoroastrianism_religion
			rite = { rite_has_parameter = eastern_syncretic_actor }
		}
	}
}

eastern_or_syncretic_with_eastern_trigger = {
	$CHARACTER$ = {
		OR = {
			faith.religion = { is_in_family = rf_eastern }
			rite = { rite_has_parameter = eastern_syncretic_actor }
		}
	}
}

sinitic_or_syncretic_with_sinitic_trigger = {
	$CHARACTER$ = {
		OR = {
			faith.religion = { is_in_family = rf_sinitic }
			rite = { rite_has_parameter = sinitic_syncretic_actor }
		}
	}	
}

hindu_or_syncretic_with_eastern_trigger = {
	$CHARACTER$ = {
		OR = {
			faith.religion = religion:hinduism_religion
			rite = { rite_has_parameter = eastern_syncretic_actor }
		}
	}	
}

jain_or_syncretic_with_eastern_trigger = {
	$CHARACTER$ = {
		OR = {
			faith.religion = religion:jainism_religion
			rite = { rite_has_parameter = eastern_syncretic_actor }
		}
	}
}

holy_site_adoptable_by_character_trigger = {
	any_holy_site_faith = {
		save_temporary_scope_as = compare_faith
		OR = {
			$CHARACTER$.rite = { rite_has_parameter = allow_adopt_any_holy_site }
			AND = {
				OR = {
					religion = $CHARACTER$.faith.religion
					$CHARACTER$.faith = {
						faith_is_syncretic_with = {
							FAITH = scope:compare_faith
						}
					}
				}
				$CHARACTER$.faith = {
					faith_hostility_level = {
						target = prev
						value <= faith_astray_level
					}
				}
			}
		}
	}
}

# Faith is the scope here
faith_has_free_holy_site_action_trigger = {
	trigger_if = {
		limit = { has_variable = free_holy_site_actions }
		var:free_holy_site_actions >= 1
	}
	trigger_else = {
		always = no
	}
}

# BARONY = the candidate holy site's barony title, in faith scope
# One created or adopted holy site per de jure kingdom
faith_holy_site_kingdom_unused_trigger = {
	trigger_if = {
		limit = {
			has_variable_list = dynamic_holy_site_kingdoms
			exists = $BARONY$.kingdom
		}
		NOT = {
			is_target_in_variable_list = {
				name = dynamic_holy_site_kingdoms
				target = $BARONY$.kingdom
			}
		}
	}
}

# As above, with the player-facing requirement line. Root must be the acting character.
faith_can_use_holy_site_kingdom_trigger = {
	custom_tooltip = {
		text = holy_site_kingdom_already_used_tt
		faith_holy_site_kingdom_unused_trigger = { BARONY = $BARONY$ }
	}
}

has_particular_personal_deity_group = {
	OR = {
		trigger_if = {
			limit = { has_fp1_dlc_trigger = yes }
			religion = religion:germanic_religion
		}
		religion = religion:hinduism_religion
		religion = religion:buddhism_religion
	}
}

has_any_syncretism_personal_tenet_trigger = {
	OR = {
		has_personal_tenet = tenet_eastern_syncretism
		has_personal_tenet = tenet_unreformed_syncretism
		has_personal_tenet = tenet_christian_syncretism
		has_personal_tenet = tenet_islamic_syncretism
		has_personal_tenet = tenet_jewish_syncretism
		has_personal_tenet = tenet_sinitic_syncretism
	}
}

# can_pick only check when you pick, so amount = 0
unique_syncretism_trigger = {
	custom_description = {
		text = incompatible_tenet_other_syncretism_trigger
		NOR = {
			tenet:tenet_eastern_syncretism = { is_in_list = selected_doctrines }
			tenet:tenet_unreformed_syncretism = { is_in_list = selected_doctrines }
			tenet:tenet_christian_syncretism = { is_in_list = selected_doctrines }
			tenet:tenet_islamic_syncretism = { is_in_list = selected_doctrines }
			tenet:tenet_jewish_syncretism = { is_in_list = selected_doctrines }
			tenet:tenet_sinitic_syncretism = { is_in_list = selected_doctrines }
		}
	}
}
unique_christology_trigger = {
	custom_tooltip = {
		text = INCOMPATIBLE_TENET_OTHER_CHRISTOLOGY_TRIGGER
		NOR = {
			tenet:tenet_adoptionism = { is_in_list = selected_doctrines }
			tenet:tenet_miaphysitism = { is_in_list = selected_doctrines }
			tenet:tenet_monophysitism = { is_in_list = selected_doctrines }
		}
	}
}
unique_christology_personal_trigger = {
	trigger_if = {
		limit = { has_global_variable = game_has_started }
		custom_tooltip = {
			text = INCOMPATIBLE_TENET_OTHER_CHRISTOLOGY_TRIGGER
			NOR = {
				has_personal_tenet = tenet_adoptionism
				has_personal_tenet = tenet_miaphysitism
				has_personal_tenet = tenet_monophysitism
			}
		}
	}
	trigger_else = {
		# prevent startup assert error
		custom_tooltip = {
			text = INCOMPATIBLE_TENET_OTHER_CHRISTOLOGY_TRIGGER
			calc_true_if = {
				amount <= 1
				has_personal_tenet = tenet_adoptionism
				has_personal_tenet = tenet_miaphysitism
				has_personal_tenet = tenet_monophysitism
			}
		}
	}
}

#Used on faiths
is_dharmic_faith_trigger = {
	OR = {
		religion = religion:hinduism_religion
		religion = religion:buddhism_religion
		religion = religion:jainism_religion
	}
}

#Used on provinces
has_holy_building = {
	has_building_with_flag = holy_building #Replaces manually maintained list of all holy buildings
}

is_faith_dominant_gender = {
	OR = {
		AND = {
			is_male = yes
			rite = {
				OR = {
					rite_has_parameter = male_dominated_law
					rite_has_parameter = gender_equal_law
				}
			}
		}
		AND = {
			is_female = yes
			rite = {
				OR = {
					rite_has_parameter = female_dominated_law
					rite_has_parameter = gender_equal_law
				}
			}
		}
	}
}

religion_is_broadly_asian_trigger = {
	OR = {
		religion_is_east_asian_trigger = yes
		broadly_dharmic_trigger = yes
		broadly_chinese_religion_trigger = yes
	}
}

religion_is_east_asian_trigger = {
	OR = {
		faith.religion = religion:buddhism_religion
		faith.religion = religion:confucianism_religion
		faith.religion = religion:taoism_religion
		faith.religion = religion:shintoism_religion
	}
}

religion_is_non_norse_european_pagan_trigger = {
	OR = {
		faith.religion = religion:baltic_religion
		faith.religion = religion:finno_ugric_religion
		faith.religion = religion:germanic_religion
		faith.religion = religion:paganism_religion
		faith.religion = religion:slavic_religion
	}
}

non_dharmic_east_asia_trigger = {
	OR = {
		faith.religion = religion:shintoism_religion	
		faith.religion = religion:dualism_religion
		faith.religion = religion:bon_religion
		faith.religion = religion:dab_qhuas_religion
		faith.religion = religion:aluk_religion
		faith.religion = religion:dayawism_religion
		faith.religion = religion:hantuism_religion
		faith.religion = religion:kaharingan_religion
		faith.religion = religion:satsana_phi_religion
		faith.religion = religion:tolotang_religion
		faith.religion = religion:utaki_religion
		faith.religion = religion:bimoism_religion
		faith.religion = religion:moism_religion
		faith.religion = religion:muism_religion
		faith.religion = religion:qiangic_religion
	}
}

religion_is_pagan_steppe = {
	OR = {
		faith.religion = religion:tengrism_religion
		faith.religion = religion:magyar_religion
		faith.religion = religion:siberian_religion
		faith.religion = religion:shamanism_religion
		faith.religion = religion:kamuyism_religion
	}
}

broadly_dharmic_faith_trigger = {
	OR = {
		religion = religion:buddhism_religion
		religion = religion:hinduism_religion
		religion = religion:jainism_religion
		religion = religion:bon_religion
		religion = religion:dab_qhuas_religion
		religion = religion:aluk_religion
		religion = religion:dayawism_religion
		religion = religion:hantuism_religion
		religion = religion:kaharingan_religion
		religion = religion:satsana_phi_religion
		religion = religion:tolotang_religion
		religion = religion:utaki_religion
		religion = religion:bimoism_religion
		religion = religion:moism_religion
		religion = religion:muism_religion
		religion = religion:qiangic_religion
	}
}

broadly_dharmic_trigger = {
	faith = {
		broadly_dharmic_faith_trigger = yes
	}
}

south_east_asian_pagan_trigger = {
	OR = {
		faith.religion = religion:aluk_religion
		faith.religion = religion:dayawism_religion
		faith.religion = religion:hantuism_religion
		faith.religion = religion:kaharingan_religion
		faith.religion = religion:tolotang_religion
		faith.religion = religion:biliku_religion
	}
}

broadly_jungle_dwelling_trigger = {
	culture = {
		OR = {
			has_cultural_pillar = heritage_austronesian
			has_cultural_pillar = heritage_burman
			has_cultural_pillar = heritage_tai
			has_cultural_pillar = heritage_hmongic
			has_cultural_pillar = heritage_dravidian
			has_cultural_pillar = heritage_mon_khmer
			has_cultural_pillar = heritage_viet
			has_cultural_pillar = heritage_indo_aryan
		}
	}
}

broadly_chinese_religion_trigger = {
	OR = {
		faith.religion = religion:taoism_religion
		faith.religion = religion:confucianism_religion
	}
}

broadly_mainland_east_asian_heritage_trigger = {
	culture = {
		OR = {
			has_cultural_pillar = heritage_chinese
			has_cultural_pillar = heritage_korean
			has_cultural_pillar = heritage_buyeo
			has_cultural_pillar = heritage_qiangic
			has_cultural_pillar = heritage_viet
		}
	}
}

broadly_japanese_island_heritage_trigger = {
	culture = {
		OR = {
			has_cultural_pillar = heritage_japonic
			has_cultural_pillar = heritage_ainuic
		}
	}
}

potential_abbot_trigger = {
	has_trait = devoted
	is_adult = yes
	faith = root.faith
	rite = root.rite
	NOT = {
		is_in_list = grabbed_monks
	}
	basic_is_available_ai = yes
	NOT = {
		has_any_bad_relationship_with_character_trigger = { CHARACTER = scope:founder }
	}
	trigger_if = {
		limit = {
			exists = scope:leader.primary_title
		}
		OR = {
			AND = {
				is_female = yes
				scope:leader.primary_title = {
					NOT = { has_variable = male_order }
				}
			}
			AND = {
				is_female = no
				scope:leader.primary_title = {
					NOT = { has_variable = female_order }
				}
			}
		}
	}
	trigger_if = {
		limit = {
			exists = scope:monk_grabbin_tenet
		}
		OR = {
			any_personal_tenet = {
				this = scope:monk_grabbin_tenet
			}
			any_desired_tenet = {
				selection_count = 97
				only_positive = yes
				threshold = 1
				this = scope:monk_grabbin_tenet
			}
		}
	}
}

#Has a sinful or a shunned trait - IS PRETTY BAD, NOT STRAIGHT UP EVIL
#Meant to be used in character scope
#needs scope of the rite they're being judged by - not necessarily their own rite
character_considered_morally_dubious_trigger = {
	save_temporary_scope_as = judged

	#Check they aren't considered so pious it excuses their sins...
	trigger_if = {
		limit = {
			rite = $RITE$
			is_ruler = yes # Performance reasons, avoids 5 trait array lookups
		}
		NOR = {
			piety_level >= 5
			has_trait = saint
			has_trait = herald
			has_trait = chakravarti
			has_trait = saoshyant
			has_trait = savior
		}
	}
	
	OR = {
		#Things that make just same-rite people mad
		trigger_if = {
			limit = {
				rite = $RITE$
			}
			piety_level < 1
		}
		#A rite the judge holds at evil-level hostility makes its adherents dubious outright, judged rite-to-rite rather than faith-to-faith.
		trigger_else = {
			$RITE$ = {
				save_temporary_scope_as = moral_dubious_judge_rite
			}
			scope:moral_dubious_judge_rite = {
				"rite_hostility_level(scope:judged.rite)" >= faith_evil_level
			}
		}
		AND = {
			has_trait = heresiarch
			NOT = {
				rite = $RITE$
			}
		}

		#SIN TRAITS - counted by the judging rite's reckoning, not the judged character's own
		num_sinful_traits = {
			target = $RITE$
			value >= 2
		}
		#Sins outweigh virtue
		AND = {
			num_sinful_traits = {
				target = $RITE$
				value >= 1
			}
			num_virtuous_traits = {
				target = $RITE$
				value = 0
			}
		}

		#SHUNNED TRAITS
		AND = {
			trait_is_shunned_in_rite_trigger = {
				RITE = $RITE$
				TRAIT = trait:sodomite
				GENDER_CHARACTER = scope:judged
			}
			has_trait = sodomite
		}
		AND = {
			trait_is_shunned_in_rite_trigger = {
				RITE = $RITE$
				TRAIT = trait:deviant
				GENDER_CHARACTER = scope:judged
			}
			has_trait = deviant
		}
		AND = {
			trait_is_shunned_in_rite_trigger = {
				RITE = $RITE$
				TRAIT = trait:adulterer
				GENDER_CHARACTER = scope:judged
			}
			has_trait = adulterer
		}
		AND = {
			trait_is_shunned_in_rite_trigger = {
				RITE = $RITE$
				TRAIT = trait:fornicator
				GENDER_CHARACTER = scope:judged
			}
			OR = {
				has_trait = fornicator
				has_trait = rakish
			}
		}
		AND = {
			trait_is_shunned_in_rite_trigger = {
				RITE = $RITE$
				TRAIT = trait:witch
				GENDER_CHARACTER = scope:judged
			}
			has_trait = witch
		}
		AND = {
			trait_is_shunned_in_rite_trigger = {
				RITE = $RITE$
				TRAIT = trait:kinslayer_1
				GENDER_CHARACTER = scope:judged
			}
			has_trait = kinslayer_1
		}
		AND = {
			trait_is_shunned_in_rite_trigger = {
				RITE = $RITE$
				TRAIT = trait:kinslayer_2
				GENDER_CHARACTER = scope:judged
			}
			has_trait = kinslayer_2
		}
		AND = {
			trait_is_shunned_in_rite_trigger = {
				RITE = $RITE$
				TRAIT = trait:kinslayer_3
				GENDER_CHARACTER = scope:judged
			}
			has_trait = kinslayer_3
		}

		#Generally questionable traits (virtue read from judge rite $RITE$)
		AND = {
			has_trait = lunatic
			NOR = {
				$RITE$ = {
					trait_is_virtue_rite = lunatic_1
				}
				$RITE$ = {
					trait_is_virtue_rite = lunatic_genetic
				}
			}
		}
		AND = {
			has_trait = gallowsbait
			NOT = {
				$RITE$ = {
					trait_is_virtue_rite = gallowsbait
				}
			}
		}
		AND = {
			has_trait = despoiler_of_byzantium
			NOT = {
				$RITE$ = {
					trait_is_virtue_rite = despoiler_of_byzantium
				}
			}
		}
		AND = {
			has_trait = disloyal
			NOT = {
				$RITE$ = {
					trait_is_virtue_rite = disloyal
				}
			}
		}
	}
}

#Has multiple sins or a criminal trait - IS EVIL
#Meant to be used in character scope
#needs scope of the rite they're being judged by - not necessarily their own rite
character_considered_wicked_trigger = {
	save_temporary_scope_as = judged
	trigger_if = {
		limit = {
			rite = $RITE$
			is_ruler = yes # Performance reasons, avoids 5 trait array lookups
		}
		NOR = {
			piety_level >= 4
			has_trait = saint
			has_trait = herald
			has_trait = chakravarti
			has_trait = saoshyant
			has_trait = savior
		}
	}

	OR = {
		#Things that make just same-rite people mad
		trigger_if = {
			limit = {
				rite = $RITE$
			}
			has_trait = excommunicated
		}
		#SIN TRAITS
		num_sinful_traits >= 3

		#HERETICAL RITE
		AND = {
			rite ?= {
				save_temporary_scope_as = wicked_judged_rite
			}
			$RITE$ = {
				"divergence(scope:wicked_judged_rite)" >= faith.heresy_threshold
			}
		}

		#CRIMINAL TRAITS
		AND = {
			trait_is_criminal_in_rite_trigger = {
				RITE = $RITE$
				TRAIT = trait:sodomite
				GENDER_CHARACTER = scope:judged
			}
			has_trait = sodomite
		}
		AND = {
			trait_is_criminal_in_rite_trigger = {
				RITE = $RITE$
				TRAIT = trait:deviant
				GENDER_CHARACTER = scope:judged
			}
			has_trait = deviant
		}
		AND = {
			trait_is_criminal_in_rite_trigger = {
				RITE = $RITE$
				TRAIT = trait:adulterer
				GENDER_CHARACTER = scope:judged
			}
			has_trait = adulterer
		}
		AND = {
			trait_is_criminal_in_rite_trigger = {
				RITE = $RITE$
				TRAIT = trait:fornicator
				GENDER_CHARACTER = scope:judged
			}
			OR = {
				has_trait = fornicator
				has_trait = rakish
			}
		}
		AND = {
			trait_is_criminal_in_rite_trigger = {
				RITE = $RITE$
				TRAIT = trait:witch
				GENDER_CHARACTER = scope:judged
			}
			has_trait = witch
		}
		AND = {
			trait_is_criminal_in_rite_trigger = {
				RITE = $RITE$
				TRAIT = trait:kinslayer_1
				GENDER_CHARACTER = scope:judged
			}
			has_trait = kinslayer_1
		}
		AND = {
			trait_is_criminal_in_rite_trigger = {
				RITE = $RITE$
				TRAIT = trait:kinslayer_2
				GENDER_CHARACTER = scope:judged
			}
			has_trait = kinslayer_2
		}
		AND = {
			trait_is_criminal_in_rite_trigger = {
				RITE = $RITE$
				TRAIT = trait:kinslayer_3
				GENDER_CHARACTER = scope:judged
			}
			has_trait = kinslayer_3
		}
		
		AND = {
			has_trait = murderer
			NOT = {
				$RITE$ = {
					trait_is_virtue_rite = murderer
				}
			}
		}
		AND = {
			has_trait = cannibal
			NOT = {
				$RITE$ = {
					trait_is_virtue_rite = cannibal
				}
			}
		}
		AND = {
			has_trait = gallowsbait
			OR = {
				has_trait_xp = {
					trait = gallowsbait
					track = bandit
					value >= 60
				}
				has_trait_xp = {
					trait = gallowsbait
					track = thief
					value >= 80
				}
				has_trait_xp = {
					trait = gallowsbait
					track = poacher
					value >= 80
				}
				has_trait_xp = {
					trait = gallowsbait
					track = trickster
					value >= 80
				}
				has_trait_xp = {
					trait = gallowsbait
					track = marauder
					value >= 40
				}
			}
			NOT = {
				$RITE$ = {
					trait_is_virtue_rite = gallowsbait
				}
			}
		}
	}
}

#The whole spectrum of badness in one trigger
character_considered_morally_dubious_or_wicked_trigger = {
	OR = {
		character_considered_wicked_trigger = { RITE = $RITE$ }
		character_considered_morally_dubious_trigger = { RITE = $RITE$ }
	}
}

rite_embraces_the_secular_flesh_trigger = {
	OR = {
		AND = {
			trait_is_virtue_rite = lustful
			$CHARACTER$.rite = { NOT = { trait_is_virtue_rite = lustful } }
		}
		AND = {
			trait_is_sin_rite = chaste
			$CHARACTER$.rite = { NOT = { trait_is_sin_rite = chaste } }
		}
		#you are a gay person... and their take on the gays is better than yours
		trigger_if = {
			limit = {
				$CHARACTER$ = {
					OR = {
						has_sexuality = homosexual
						has_sexuality = bisexual
					}
					rite = { NOT = { rite_has_parameter = homosexuality_accepted } }
				}
			}
			OR = {
				rite_has_parameter = homosexuality_accepted
				AND = {
					rite_has_parameter = homosexuality_shunned
					$CHARACTER$.rite = { rite_has_parameter = homosexuality_illegal }
				}
			}
		}
		#You are female and female adultery is a soft yes 
		trigger_if = {
			limit = {
				$CHARACTER$ = {
					is_female = yes
					rite = { NOT = { rite_has_parameter = adultery_female_accepted } }
				}
			}
			OR = {
				rite_has_parameter = adultery_female_accepted
				AND = {
					rite_has_parameter = adultery_female_shunned
					$CHARACTER$.rite = { rite_has_parameter = adultery_female_crime }
				}
			}
		}
		#You are male and male adultery is a soft yes
		trigger_if = {
			limit = {
				$CHARACTER$ = {
					is_male = yes
					rite = { NOT = { rite_has_parameter = adultery_male_accepted } }
				}
			}
			OR = {
				rite_has_parameter = adultery_male_accepted
				AND = {
					rite_has_parameter = adultery_male_shunned
					$CHARACTER$.rite = { rite_has_parameter = adultery_male_crime }
				}
			}
		}
	}
}
#Check how your rite views YOUR horny activities
rite_forbids_the_secular_flesh_trigger = {
	OR = {
		AND = {
			trait_is_virtue_rite = chaste
			$CHARACTER$.rite = { NOT = { trait_is_virtue_rite = chaste } }
		}
		AND = {
			trait_is_sin_rite = lustful
			$CHARACTER$.rite = { NOT = { trait_is_sin_rite = lustful } }
		}
		#you are a gay person... and their take on the gays is crueler than yours
		trigger_if = {
			limit = {
				$CHARACTER$ = {
					OR = {
						has_sexuality = homosexual
						has_sexuality = bisexual
					}
					rite = { NOT = { rite_has_parameter = homosexuality_illegal } }
				}
			}
			OR = {
				rite_has_parameter = homosexuality_illegal
				AND = {
					rite_has_parameter = homosexuality_shunned
					$CHARACTER$.rite = { rite_has_parameter = homosexuality_accepted }
				}
			}
		}
		#You are female and female adultery is a hard no
		trigger_if = {
			limit = {
				$CHARACTER$ = {
					is_female = yes
					rite = { NOT = { rite_has_parameter = adultery_female_crime } }
				}
			}
			OR = {
				rite_has_parameter = adultery_female_crime
				AND = {
					rite_has_parameter = adultery_female_shunned
					$CHARACTER$.rite = { rite_has_parameter = adultery_female_accepted }
				}
			}
		}
		#You are male and male adultery is a hard no
		trigger_if = {
			limit = {
				$CHARACTER$ = {
					is_male = yes
					rite = { NOT = { rite_has_parameter = adultery_male_crime } }
				}
			}
			OR = {
				rite_has_parameter = adultery_male_crime
				AND = {
					rite_has_parameter = adultery_male_shunned
					$CHARACTER$.rite = { rite_has_parameter = adultery_male_accepted }
				}
			}
		}
	}
}

###Demand Church Succession###
# True if the actor's diocese (clerical_region) is the same as TARGET's diocese.
is_in_same_clerical_region_as_trigger = {
	exists = $TARGET$.capital_county.clerical_region_title
	capital_county.clerical_region_title ?= $TARGET$.capital_county.clerical_region_title
}

is_valid_demand_church_succession_target_trigger = {
	OR = {
		government_has_flag = government_is_feudal
		government_has_flag = government_is_clan
		government_has_flag = government_is_tribal       # also covers wanua (which carries government_is_tribal)
		government_has_flag = government_is_japan_feudal
		government_has_flag = government_is_mandala
	}
}

# Demand Divorce offences, shared by AI targeting and event text
# Same checks as divorce_character_ai_accept_modifier
demand_divorce_marriage_incestuous_trigger = {
	$RULER$ = {
		relation_with_character_is_incestuous_in_my_faith_trigger = { CHARACTER = $SPOUSE$ }
	}
}

demand_divorce_spouse_heathen_trigger = {
	$RULER$.faith.religion != $SPOUSE$.faith.religion
}

demand_divorce_spouse_heretic_trigger = {
	$RULER$.faith.religion = $SPOUSE$.faith.religion
	$SPOUSE$ = {
		faith != $RULER$.faith
	}
}

demand_divorce_spouse_infidelity_trigger = {
	$SPOUSE$ = {
		exposed_cheating_on_spouse_trigger = { SPOUSE = $RULER$ }
	}
}

demand_divorce_marriage_same_sex_trigger = {
	$RULER$ = {
		sex_same_as = $SPOUSE$
		allowed_to_marry_same_sex_trigger = no
	}
}

demand_divorce_marriage_polygamous_trigger = {
	$RULER$ = {
		any_consort = {
			is_alive = yes
			this != $SPOUSE$
		}
		any_consort = {
			this = $SPOUSE$
		}
	}
	$SPOUSE$.culture = { NOT = { has_cultural_tradition = tradition_polygamous } }
	$SPOUSE$.rite = { NOT = { rite_has_doctrine = doctrine_polygamy } }
}

demand_divorce_marriage_offensive_trigger = {
	OR = {
		demand_divorce_marriage_incestuous_trigger = { RULER = $RULER$ SPOUSE = $SPOUSE$ }
		demand_divorce_marriage_same_sex_trigger = { RULER = $RULER$ SPOUSE = $SPOUSE$ }
		demand_divorce_spouse_heathen_trigger = { RULER = $RULER$ SPOUSE = $SPOUSE$ }
		demand_divorce_spouse_heretic_trigger = { RULER = $RULER$ SPOUSE = $SPOUSE$ }
		demand_divorce_spouse_infidelity_trigger = { RULER = $RULER$ SPOUSE = $SPOUSE$ }
		demand_divorce_marriage_polygamous_trigger = { RULER = $RULER$ SPOUSE = $SPOUSE$ }
	}
}

############################
# Faith Rite Growth System #
############################

rite_growth_founder_is_archbishop_trigger = {
	scope:founder = {
		any_held_title = { has_clerical_region = yes }
	}
}

# Character scope. Holds a see with enough counties for a spawned rite to have somewhere to spread.
rite_growth_holds_sizable_clerical_region_trigger = {
	any_held_title = {
		has_clerical_region = yes
		clerical_region_size >= rite_growth_min_clerical_region_size
	}
}

# Character scope, requires scope:founder
rite_growth_in_founder_spread_area_trigger = {
	exists = capital_county
	exists = cp:councillor_court_chaplain
	trigger_if = {
		limit = { rite_growth_founder_is_archbishop_trigger = yes }
		OR = {
			AND = {
				is_landed = yes
				faith = { has_doctrine_parameter = has_clerical_regions }
				exists = capital_county.clerical_region_title
				scope:founder.capital_county.clerical_region_title ?= capital_county.clerical_region_title
			}
			AND = {
				is_landed = yes
				exists = scope:founder.capital_county
				capital_county = {
					squared_distance = {
						target = scope:founder.capital_county
						value <= squared_distance_small
					}
				}
			}
		}
	}
	trigger_else = {
		OR = {
			is_vassal_or_below_of = scope:founder
			AND = {
				is_landed = yes
				exists = scope:founder.capital_county
				capital_county = {
					squared_distance = {
						target = scope:founder.capital_county
						value <= squared_distance_small
					}
				}
			}
		}
	}
}

# Founder eligibility for spawning a new rite
is_eligible_rite_growth_founder_trigger = {
	is_available_ai_adult = yes
	rite = scope:source_rite
	learning >= medium_skill_rating
	NOR = {
		has_trait = heresiarch
		has_trait = herald
		recently_converted_faith_trigger = yes
		has_character_flag = recently_converted_by_rite_growth
		faith.religious_head ?= this
		scope:source_rite.head_of_rite ?= this
		highest_held_title_tier >= tier_empire
		government_has_flag = government_is_nomadic
		government_has_flag = government_is_herder
	}
	OR = {
		AND = {
			is_landed = yes
			highest_held_title_tier >= tier_duchy
			any_held_title = {
				tier = tier_county
				rite = scope:source_rite
			}
		}
		any_held_title = { has_clerical_region = yes }
	}
}

# AI sweep-target eligibility for rite_growth.0011
is_eligible_rite_growth_target_trigger = {
	is_physically_able_ai_adult = yes
	rite = scope:source_rite
	NOR = {
		scope:founder ?= this
		has_trait = heresiarch
		has_trait = herald
		recently_converted_faith_trigger = yes
		has_character_flag = recently_converted_by_rite_growth
		has_character_flag = ai_will_not_convert
		this = faith.religious_head
		scope:source_rite.head_of_rite ?= this
		highest_held_title_tier >= tier_empire
	}
	OR = {
		AND = {
			is_landed = yes
			highest_held_title_tier >= tier_county
			any_held_title = {
				tier = tier_county
				OR = {
					rite = scope:source_rite
					rite = scope:new_rite
				}
			}
		}
		any_held_title = { has_clerical_region = yes }
	}
}

# Everyone who doesn't fulfil this gets to include_unknown = yes
rite_growth_founder_is_well_versed_trigger = {
	tenets_doctrines_unknown_to_faith >= 5
}

rite_growth_tenet_is_unique_to_new_rite_trigger = {
	save_temporary_scope_as = candidate_tenet
	scope:source_rite = { NOT = { rite_has_tenet = scope:candidate_tenet } }
}

rite_growth_doctrine_is_unique_to_new_rite_trigger = {
	save_temporary_scope_as = candidate_doctrine
	scope:new_rite = { rite_has_doctrine = scope:candidate_doctrine }
	scope:source_rite = { NOT = { rite_has_doctrine = scope:candidate_doctrine } }
}

rite_growth_founder_is_meaningful_relation_trigger = {
	OR = {
		is_close_or_extended_family_of = scope:founder
		any_spouse = { this = scope:founder }
		any_consort = { this = scope:founder }
		betrothed ?= scope:founder
		has_relation_friend = scope:founder
		has_relation_lover = scope:founder
		has_relation_potential_lover = scope:founder
		has_relation_rival = scope:founder
		liege ?= scope:founder
		scope:founder.liege ?= root
		AND = {
			exists = scope:founder.dynasty
			dynasty ?= scope:founder.dynasty
		}
	}
}

# Can edit a rite
can_edit_rite_trigger = {
	is_adult = yes
	is_at_war = no
	custom_tooltip = {
		text = ecumenical_council_already_ongoing_tt
		NOT = { faith = { has_variable = ecumenical_council_ongoing } }
	}
	trigger_if = {
		limit = {
			is_clergy = no
			highest_held_title_tier = tier_county
			top_liege != this
		}
		custom_description = {
			text = "faith_creation_duchy_or_higher"
			highest_held_title_tier >= tier_duchy
		}
	}

	trigger_if = {
		limit = {
			rite = {
				rite_has_doctrine = doctrine_theocracy_temporal
			}
			is_clergy = no
			has_puppet_type = theological_agent_puppet
			# Allow Mandala God-Kings and Son of Heaven to create and edit rites freely
			trigger_if = {
				limit = {
					top_overlord = this
				}
				NOR = {
					government_has_flag = government_is_mandala
					tgp_has_access_to_ministry_trigger = yes
				}
			}
		}
		is_puppet_action_valid = puppet_trigger_can_create_rite
	}
	
	custom_description = {
		text = "character_is_rite_head"
		rite.head_of_rite == root
	}

	custom_description = {
		text = "character_can_only_edit_one_rite"
		NOT = { exists = var:has_edited_a_rite }
	}

	trigger_if = {
		limit = {
			faith = { has_doctrine_parameter = unreformed }
		}

		NOT = {
			custom_description = {
				text = faith_has_been_reformed
				object = faith
				exists = faith.var:has_been_reformed
			}
		}

		trigger_if = {
			limit = {
				NOT = {
					has_character_flag = ignore_3_holy_site_rule
				}
			}
			# Empire Faith Gate: easier reformation path
			trigger_if = {
				limit = {
					empire_faith_gate_enabled_trigger = yes
				}
				custom_tooltip = {
					text = empire_faith_gate_reformation_piety_level
					piety_level >= 2
				}
				custom_tooltip = {
					text = empire_faith_gate_reformation_tribal_authority
					has_realm_law = tribal_authority_3
				}
				custom_tooltip = {
					text = empire_faith_gate_reformation_holy_site
					faith = {
						any_holy_site_barony = {
							count >= 3
							county.holder = {
								faith = root.faith
							}
						}
					}
				}
			}
			# Vanilla: 3 holy sites
			trigger_else = {
				faith = {
					num_realm_holy_sites_faithful_holders = {
						CHARACTER = root
						COUNT = 3
					}
				}
			}
		}

		custom_tooltip = {
			text = faith_reformation_via_decision
			faith = {
				NOT = { has_variable = block_reformation_var }
			}
		}
	}
}

# Can create a rite
can_create_rite_trigger = {

	is_adult = yes
	is_at_war = no
	
	trigger_if = {
		limit = {
			is_clergy = no
			highest_held_title_tier = tier_county
			top_liege != this
		}
		custom_description = {
			text = "faith_creation_duchy_or_higher"
			highest_held_title_tier >= tier_duchy
		}
	}

	trigger_if = {
		limit = {
			rite = {
				rite_has_doctrine = doctrine_theocracy_temporal
			}
			is_clergy = no
			has_puppet_type = theological_agent_puppet
			# Allow Mandala God-Kings and Son of Heaven to create and edit rites freely
			trigger_if = {
				limit = {
					top_overlord = this
				}
				NOR = {
					government_has_flag = government_is_mandala
					tgp_has_access_to_ministry_trigger = yes
				}
			}
		}
		is_puppet_action_valid = puppet_trigger_can_create_rite
	}
	
	custom_description = {
		text = "character_is_not_real_head"
		faith.religious_head != root
	}

	custom_description = {
		text = "character_can_only_create_one_rite"
		NOT = { exists = var:has_created_a_faith }
	}

	trigger_if = {
		limit = {
			faith = { has_doctrine_parameter = unreformed }
		}

		NOT = {
			custom_description = {
				text = faith_has_been_reformed
				object = faith
				exists = faith.var:has_been_reformed
			}
		}

		trigger_if = {
			limit = {
				NOT = {
					has_character_flag = ignore_3_holy_site_rule
				}
			}
			# Empire Faith Gate: easier reformation path
			trigger_if = {
				limit = {
					empire_faith_gate_enabled_trigger = yes
				}
				custom_tooltip = {
					text = empire_faith_gate_reformation_piety_level
					piety_level >= 2
				}
				custom_tooltip = {
					text = empire_faith_gate_reformation_tribal_authority
					has_realm_law = tribal_authority_3
				}
				custom_tooltip = {
					text = empire_faith_gate_reformation_holy_site
					faith = {
						any_holy_site_barony = {
							count >= 3
							county.holder = {
								faith = root.faith
							}
						}
					}
				}
			}
			# Vanilla: 3 holy sites
			trigger_else = {
				faith = {
					num_realm_holy_sites_faithful_holders = {
						CHARACTER = root
						COUNT = 3
					}
				}
			}
		}

		custom_tooltip = {
			text = faith_reformation_via_decision
			faith = {
				NOT = { has_variable = block_reformation_var }
			}
		}
	}
}

spiritual_hof_or_realm_priest_superior_recipient_trigger = {
	#If there are no superiors (867), just their own bishop is fine...
	trigger_if = {
		limit = {
			NOR = {
				AND = {
					religious_head_or_challenger ?= scope:recipient
					faith = {
						has_doctrine = doctrine_spiritual_head
					}
				}
				exists = cp:councillor_court_chaplain.superior
				AND = {
					government_has_flag = government_is_theocracy
					exists = superior
				}
			}
		}
		custom_tooltip = {
			text = duke_plus_court_chaplain_tt
			cp:councillor_court_chaplain ?= {
				highest_held_title_tier >= tier_duchy
				government_has_flag = government_is_theocracy
			}
		}
		
	}
	trigger_else = {
		custom_tooltip = {
			text = superior_or_spiritual_hof_tt
			OR = {
				AND = {
					religious_head_or_challenger = scope:recipient
					faith = {
						has_doctrine = doctrine_spiritual_head
					}
				}
				cp:councillor_court_chaplain ?= {
					superior ?= scope:recipient
				}
				AND = {
					government_has_flag = government_is_theocracy
					superior ?= scope:recipient
				}
			}
		}
	}
}

hof_or_realm_priest_superior_recipient_trigger = {
	#If there are no superiors (867), just their own bishop is fine...
	trigger_if = {
		limit = {
			NOR = {
				exists = faith.religious_head
				exists = cp:councillor_court_chaplain.superior
				AND = {
					government_has_flag = government_is_theocracy
					exists = superior
				}
			}
		}
		custom_tooltip = {
			text = duke_plus_court_chaplain_tt
			cp:councillor_court_chaplain ?= {
				highest_held_title_tier >= tier_duchy
				government_has_flag = government_is_theocracy
			}
		}
		
	}
	trigger_else = {
		custom_tooltip = {
			text = superior_or_hof_tt
			OR = {
				faith = {
					religious_head ?= scope:recipient
				}
				cp:councillor_court_chaplain ?= {
					superior ?= scope:recipient
				}
				AND = {
					government_has_flag = government_is_theocracy
					superior ?= scope:recipient
				}
			}
		}
	}
}
broader_clergy_show_hof_or_superior_interactions_trigger = {
	OR = {
		religious_head_or_challenger ?= scope:recipient
		scope:recipient = {
			is_clergy = yes
			OR = {
				AND = {
					exists = scope:puppet_or_actor.cp:councillor_court_chaplain
					this = scope:puppet_or_actor.cp:councillor_court_chaplain
				}
				is_ruler = yes
			}
		}
	}
}

need_hof_for_clergy_interaction_trigger = {
	trigger_if = {
		limit = { has_pam_dlc_trigger = yes }
		highest_held_title_tier >= tier_kingdom
	}
	trigger_else = {
		highest_held_title_tier >= tier_empire
	}
}

# Seek Indulgences: whose portrait the interaction appears on, in petitioner scope
# is_clergy misses many PAM prelates
seek_indulgences_show_recipient_trigger = {
	OR = {
		religious_head_or_challenger ?= scope:recipient
		cp:councillor_court_chaplain ?= scope:recipient
		scope:recipient = {
			is_ruler = yes
			pam_is_investiture_clergy_trigger = yes
		}
	}
}

# Actor scope: capital region archbishops resolve to themselves and do not count
seek_indulgences_has_capital_archbishop_trigger = {
	capital_county ?= {
		clerical_region_title ?= {
			holder ?= {
				NOT = { this = scope:actor }
				faith = scope:actor.faith
			}
		}
	}
}

# Seek Indulgences: a landed prelate of the petitioner's own faith within their top realm.
seek_indulgences_landed_clergy_recipient_trigger = {
	scope:recipient = {
		pam_is_investiture_landed_prelate_trigger = yes
		faith = scope:actor.faith
		top_liege ?= scope:actor.top_liege
	}
}

# Your own archbishop outranks the Head of Faith
# Archbishops themselves go to the Head of Faith, then the realm priest last
seek_indulgences_recipient_trigger = {
	trigger_if = {
		limit = {
			seek_indulgences_has_capital_archbishop_trigger = yes
			pam_is_archbishop_or_higher_trigger = no
		}
		custom_tooltip = {
			text = seek_indulgences_recipient_archbishop_tt
			OR = {
				capital_county.clerical_region_title.holder ?= scope:recipient
				seek_indulgences_landed_clergy_recipient_trigger = yes
			}
		}
	}
	trigger_else_if = {
		limit = {
			exists = religious_head_or_challenger
		}
		custom_tooltip = {
			text = seek_indulgences_recipient_head_of_faith_tt
			OR = {
				religious_head_or_challenger ?= scope:recipient
				seek_indulgences_landed_clergy_recipient_trigger = yes
			}
		}
	}
	trigger_else = {
		custom_tooltip = {
			text = seek_indulgences_recipient_realm_priest_tt
			OR = {
				cp:councillor_court_chaplain ?= scope:recipient
				seek_indulgences_landed_clergy_recipient_trigger = yes
			}
		}
	}
}

# Bishop search for the excommunicated recovery alert. Evaluated on the candidate; $ACTOR$ is the excommunicated player.
excommunicated_recovery_valid_cleric_for_actor_trigger = {
	save_temporary_scope_as = recovery_cleric
	NOT = { scope:recovery_cleric = $ACTOR$ }
	$ACTOR$ = {
		NOR = {
			petition_head_of_faith_repentance_requires_petition_trigger = yes
			has_character_modifier = recent_excommunication
			is_at_war_with = scope:recovery_cleric
		}
	}
	scope:recovery_cleric = {
		highest_held_title_tier >= tier_duchy
		OR = {
			is_clergy = yes
			government_has_flag = government_is_ecclesiastical
		}
		faith = $ACTOR$.faith
		# Only archbishops and above may name the Head of Faith here; everyone else needs a local bishop.
		$ACTOR$ = {
			trigger_if = {
				limit = { pam_is_archbishop_or_higher_trigger = no }
				NOT = { faith.religious_head ?= scope:recovery_cleric }
			}
		}
	}
}
hof_or_realm_priest_superior_actor_trigger = {
	#If there are no superiors (867), just their own bishop is fine...
	trigger_if = {
		limit = {
			NOR = {
				exists = faith.religious_head
				exists = cp:councillor_court_chaplain.superior
				AND = {
					government_has_flag = government_is_theocracy
					exists = superior
				}
			}
		}
		custom_tooltip = {
			text = duke_plus_court_chaplain_tt
			cp:councillor_court_chaplain ?= {
				highest_held_title_tier >= tier_duchy
				government_has_flag = government_is_theocracy
			}
		}
		
	}
	trigger_else = {
		custom_tooltip = {
			text = superior_or_hof_tt
			OR = {
				faith = {
					religious_head ?= scope:recipient
				}
				cp:councillor_court_chaplain ?= {
					superior ?= scope:recipient
				}
				AND = {
					government_has_flag = government_is_theocracy
					superior ?= scope:recipient
				}
			}
		}
	}
}

faith_can_have_heresy_trigger = {
	OR = {
		NOR = {
			has_doctrine = eastern_hostility_doctrine
			has_doctrine = sinitic_hostility_doctrine
		}
		has_doctrine = heresy_hostility_doctrine #Zoroastrians also get heresies, despite being Eastern.
	}
}

faith_is_in_same_rf = {
	trigger_if = {
		limit = { is_in_family = rf_abrahamic }
		$FAITH$ = { is_in_family = rf_abrahamic }
	}
	trigger_else_if = {
		limit = { is_in_family = rf_pagan }
		$FAITH$ = { is_in_family = rf_pagan }
	}
	trigger_else_if = {
		limit = { is_in_family = rf_eastern }
		$FAITH$ = { is_in_family = rf_eastern }
	}
	trigger_else_if = {
		limit = { is_in_family = rf_sinitic }
		$FAITH$ = { is_in_family = rf_sinitic }
	}
	trigger_else = {
		always = no
	}
}

faith_is_syncretic_with = {
	$FAITH$ = {
		trigger_if = {
			limit = { has_doctrine_parameter = unreformed }
			prev = { has_doctrine_parameter = unreformed_syncretic_actor }
		}
		trigger_else_if = {
			limit = { religion_tag = christianity_religion }
			prev = { has_doctrine_parameter = christian_syncretic_actor }
		}
		trigger_else_if = {
			limit = { religion_tag = islam_religion }
			prev = { has_doctrine_parameter = islamic_syncretic_actor }
		}
		trigger_else_if = {
			limit = { religion_tag = judaism_religion }
			prev = { has_doctrine_parameter = jewish_syncretic_actor }
		}
		trigger_else_if = {
			limit = { is_in_family = rf_eastern }
			prev = { has_doctrine_parameter = eastern_syncretic_actor }
		}
		trigger_else_if = {
			limit = { is_in_family = rf_sinitic }
			prev = { has_doctrine_parameter = sinitic_syncretic_actor }
		}
		trigger_else = {
			always = no
		}
	}
}

rite_is_syncretic_with = {
	$RITE$ = {
		trigger_if = {
			limit = { rite_has_parameter = unreformed }
			prev = { rite_has_parameter = unreformed_syncretic_actor }
		}
		trigger_else_if = {
			limit = { faith = { religion_tag = christianity_religion } }
			prev = { rite_has_parameter = christian_syncretic_actor }
		}
		trigger_else_if = {
			limit = { faith = { religion_tag = islam_religion } }
			prev = { rite_has_parameter = islamic_syncretic_actor }
		}
		trigger_else_if = {
			limit = { faith = { religion_tag = judaism_religion } }
			prev = { rite_has_parameter = jewish_syncretic_actor }
		}
		trigger_else_if = {
			limit = { faith = { is_in_family = rf_eastern } }
			prev = { rite_has_parameter = eastern_syncretic_actor }
		}
		trigger_else_if = {
			limit = { faith = { is_in_family = rf_sinitic } }
			prev = { rite_has_parameter = sinitic_syncretic_actor }
		}
		trigger_else = {
			always = no
		}
	}
}
